Example #1
0
        public AccVoucherMaster VoucherMasterEntity()
        {
            var objVoucherMaster = new AccVoucherMaster();

            objVoucherMaster.Id             = this.Id;
            objVoucherMaster.VoucherNo      = this.VoucherNo;
            objVoucherMaster.VoucherDate    = this.VoucherDate;
            objVoucherMaster.CompanyId      = this.CompanyId;
            objVoucherMaster.VoucherTypeId  = this.VoucherTypeId;
            objVoucherMaster.PaymentTo      = this.PaymentTo;
            objVoucherMaster.ChequeNo       = this.ChequeNo;
            objVoucherMaster.ChequeDate     = this.ChequeDate;
            objVoucherMaster.ChequeBankId   = this.ChequeBankId;
            objVoucherMaster.ReferenceNo    = this.ReferenceNo;
            objVoucherMaster.EntryType      = this.EntryType;
            objVoucherMaster.CurrencyId     = this.CurrencyId;
            objVoucherMaster.ConversionRate = this.ConversionRate;
            objVoucherMaster.Narration      = this.Narration;
            objVoucherMaster.VMonth         = this.VMonth;
            objVoucherMaster.VYear          = this.VYear;
            objVoucherMaster.SerialNo       = this.SerialNo;
            objVoucherMaster.MApproval      = this.MApproval;
            objVoucherMaster.GApproval      = this.GApproval;
            objVoucherMaster.DApproval      = this.DApproval;
            objVoucherMaster.CreatedBy      = this.CreatedBy;
            objVoucherMaster.CreatedDate    = this.CreatedDate;
            objVoucherMaster.UpdatedBy      = this.UpdatedBy;
            objVoucherMaster.UpdatedDate    = this.UpdatedDate;
            objVoucherMaster.IPAddress      = this.IPAddress;
            objVoucherMaster.IsActive       = this.IsActive;


            // objVoucherMaster.VoucherDetails = this.VoucherDetails;
            //objVoucherMaster.CmnBank = this.BankInfo;
            //objVoucherMaster.CmnCompany = this.CmnCompany;
            objVoucherMaster.AccVoucherType = this.VoucherType;

            return(objVoucherMaster);
        }
Example #2
0
        public string VoucherSave(int userId, EmVoucherType type, string voucherCode)
        {
            try
            {
                if (VoucherDetails == null)
                {
                    return("Please Provide Cash Payment Voucher Detail Information");
                }

                if (TotalDebitAmount != TotalCreditAmount)
                {
                    return("Total Debit Amount and Credit Amount must be Equal");
                }

                if (TotalDebitAmount == 0 && TotalCreditAmount == 0)
                {
                    return("Total Debit Amount and Credit Amount Zero (0) Not Allow");
                }

                Id          = Convert.ToInt32(UniqueCode.GetAutoNumber("voucher"));
                CreatedBy   = userId;
                CreatedDate = DateTime.Now;
                UpdatedBy   = userId;
                UpdatedDate = DateTime.Now;
                VoucherDate = UniqueCode.GetDateFormat_MM_dd_yyy(VoucherDateStr);
                VoucherNo   = UniqueCode.VoucherCodeGenerate(type, voucherCode, VoucherDate, CompanyId);
                SerialNo    = Convert.ToInt32(UniqueCode.GetVoucherSerialByMonth(type, VoucherDate));
                if (type == EmVoucherType.BankVoucher)
                {
                    ChequeDate  = UniqueCode.GetDateFormat_MM_dd_yyy(ChequeDateStr);
                    CreatedDate = DateTime.Now;
                }

                VoucherTypeId = (int)type;
                IsActive      = true;

                foreach (var vDetail in VoucherDetails)
                {
                    if (vDetail.CostCenterId != 0 && vDetail.AC5Id != 0)
                    {
                        if ((vDetail.DebitAmount == 0) && (vDetail.CreditAmount == 0))
                        {
                            return("Please provide at lest one amount(Debit or Credit)");
                        }


                        vDetail.TransactionType = vDetail.DebitAmount != 0 ? "Debit" : "Credit";
                        vDetail.VoucherNo       = VoucherNo;
                        vDetail.VMasterId       = Id;
                        vDetail.IsActive        = true;

                        //cpv.VoucherDetails.Add(vDetail);
                        AccVoucherDetails.Add(vDetail.VoucherDetailEntity());
                    }
                    else
                    {
                        return("Provide LedgerInfo and CostCenter in all field");
                    }
                }
                AccVoucherMaster voucherMaster = VoucherMasterEntity();
                using (var _db = new ERP_Entities())
                {
                    _db.AccVoucherDetails.AddRange(AccVoucherDetails);

                    _db.AccVoucherMasters.Add(voucherMaster);

                    _db.SaveChanges();
                }

                return("ok");
            }
            catch
            {
                return("Please provide all information");
            }
        }