Esempio n. 1
0
        public ActionResult View(long?id)
        {
            PurchaseInvoiceModel purchaseModel = new PurchaseInvoiceModel();

            if (UserRolePermissionForPage.View == true)
            {
                if (id > 0)
                {
                    long purchaseInvoiceId = Convert.ToInt64(id);
                    purchaseModel = _iPurchaseInvoiceService.GetViewPurchaseInvoiceFoodMenuById(purchaseInvoiceId);
                }
                else
                {
                    purchaseModel.ReferenceNo         = _iPurchaseInvoiceService.ReferenceNumberFoodMenu().ToString();
                    purchaseModel.PurchaseInvoiceDate = DateTime.UtcNow.AddMinutes(LoginInfo.Timeoffset);
                }
                purchaseModel.SupplierList = _iDropDownService.GetSupplierList();
                purchaseModel.StoreList    = _iDropDownService.GetStoreList();
                purchaseModel.EmployeeList = _iDropDownService.GetEmployeeList();
                return(View(purchaseModel));
            }
            else
            {
                return(RedirectToAction("NotFound", "Error"));
            }
        }
Esempio n. 2
0
        public ActionResult GetFoodMenuList()
        {
            PurchaseInvoiceModel purchaseModel = new PurchaseInvoiceModel();

            purchaseModel.FoodMenuList = _iDropDownService.GetFoodMenuListByFoodmenuType(1);
            return(Json(new { purchaseModel.FoodMenuList }));
        }
Esempio n. 3
0
        public ActionResult GetOrderById(long purchaseId)
        {
            PurchaseInvoiceModel purchaseModel = new PurchaseInvoiceModel();

            purchaseModel = _iPurchaseInvoiceService.GetPurchaseInvoiceFoodMenuById(purchaseId);
            return(View(purchaseModel));
        }
Esempio n. 4
0
        public ActionResult GetSupplierDetail(int supplierId)
        {
            SupplierModel        supplierModel = new SupplierModel();
            PurchaseInvoiceModel purchaseModel = new PurchaseInvoiceModel();

            purchaseModel.FoodMenuList = _iDropDownService.GetFoodMenuListBySupplier(supplierId);
            supplierModel = _iSupplierService.GetSupplierById(supplierId);
            return(Json(new { email = supplierModel.SupplierEmail, taxType = supplierModel.TaxType, purchaseModel.FoodMenuList }));
        }
        private async Task <PurchaseInvoiceModel> AssignValueToModel(Purchaseinvoice purchaseInvoice)
        {
            return(await Task.Run(() =>
            {
                PurchaseInvoiceModel purchaseInvoiceModel = new PurchaseInvoiceModel();

                purchaseInvoiceModel.PurchaseInvoiceId = purchaseInvoice.PurchaseInvoiceId;
                purchaseInvoiceModel.InvoiceNo = purchaseInvoice.InvoiceNo;
                purchaseInvoiceModel.InvoiceDate = purchaseInvoice.InvoiceDate;
                purchaseInvoiceModel.SupplierLedgerId = purchaseInvoice.SupplierLedgerId;
                purchaseInvoiceModel.BillToAddressId = purchaseInvoice.BillToAddressId;
                purchaseInvoiceModel.AccountLedgerId = purchaseInvoice.AccountLedgerId;
                purchaseInvoiceModel.SupplierReferenceNo = purchaseInvoice.SupplierReferenceNo;
                purchaseInvoiceModel.SupplierReferenceDate = purchaseInvoice.SupplierReferenceDate;
                purchaseInvoiceModel.CreditLimitDays = purchaseInvoice.CreditLimitDays;
                purchaseInvoiceModel.PaymentTerm = purchaseInvoice.PaymentTerm;
                purchaseInvoiceModel.Remark = purchaseInvoice.Remark;
                purchaseInvoiceModel.TaxModelType = purchaseInvoice.TaxModelType;
                purchaseInvoiceModel.TaxRegisterId = purchaseInvoice.TaxRegisterId;
                purchaseInvoiceModel.CurrencyId = purchaseInvoice.CurrencyId;
                purchaseInvoiceModel.ExchangeRate = purchaseInvoice.ExchangeRate;
                purchaseInvoiceModel.TotalLineItemAmountFc = purchaseInvoice.TotalLineItemAmountFc;
                purchaseInvoiceModel.TotalLineItemAmount = purchaseInvoice.TotalLineItemAmount;
                purchaseInvoiceModel.GrossAmountFc = purchaseInvoice.GrossAmountFc;
                purchaseInvoiceModel.GrossAmount = purchaseInvoice.GrossAmount;
                purchaseInvoiceModel.NetAmountFc = purchaseInvoice.NetAmountFc;
                purchaseInvoiceModel.NetAmount = purchaseInvoice.NetAmount;
                purchaseInvoiceModel.NetAmountFcinWord = purchaseInvoice.NetAmountFcinWord;
                purchaseInvoiceModel.TaxAmountFc = purchaseInvoice.TaxAmountFc;
                purchaseInvoiceModel.TaxAmount = purchaseInvoice.TaxAmount;
                purchaseInvoiceModel.DiscountPercentageOrAmount = purchaseInvoice.DiscountPercentageOrAmount;
                purchaseInvoiceModel.DiscountPerOrAmountFc = purchaseInvoice.DiscountPerOrAmountFc;
                purchaseInvoiceModel.DiscountAmountFc = purchaseInvoice.DiscountAmountFc;
                purchaseInvoiceModel.DiscountAmount = purchaseInvoice.DiscountAmount;
                purchaseInvoiceModel.StatusId = purchaseInvoice.StatusId;
                purchaseInvoiceModel.CompanyId = Convert.ToInt32(purchaseInvoice.CompanyId);
                purchaseInvoiceModel.FinancialYearId = Convert.ToInt32(purchaseInvoice.FinancialYearId);
                purchaseInvoiceModel.MaxNo = purchaseInvoice.MaxNo;
                purchaseInvoiceModel.VoucherStyleId = purchaseInvoice.VoucherStyleId;
                purchaseInvoiceModel.PreparedByUserId = purchaseInvoice.PreparedByUserId;
                purchaseInvoiceModel.UpdatedByUserId = purchaseInvoice.UpdatedByUserId;
                purchaseInvoiceModel.PreparedDateTime = purchaseInvoice.PreparedDateTime;
                purchaseInvoiceModel.UpdatedDateTime = purchaseInvoice.UpdatedDateTime;

                purchaseInvoiceModel.SupplierLedgerName = purchaseInvoice.SupplierLedger.LedgerName;
                purchaseInvoiceModel.BillToAddress = purchaseInvoice.BillToAddress.AddressDescription;
                purchaseInvoiceModel.AccountLedgerName = purchaseInvoice.AccountLedger.LedgerName;
                purchaseInvoiceModel.TaxRegisterName = purchaseInvoice.TaxRegister.TaxRegisterName;
                purchaseInvoiceModel.CurrencyName = purchaseInvoice.Currency.CurrencyName;
                purchaseInvoiceModel.StatusName = purchaseInvoice.Status.StatusName;
                purchaseInvoiceModel.PreparedByName = purchaseInvoice.PreparedByUser.UserName;

                return purchaseInvoiceModel;
            }));
        }
        /// <summary>
        /// create new purchase invoice.
        /// </summary>
        /// <param name="purchaseInvoiceModel"></param>
        /// <returns>
        /// return id.
        /// </returns>
        public async Task <int> CreatePurchaseInvoice(PurchaseInvoiceModel purchaseInvoiceModel)
        {
            int purchaseInvoiceId = 0;

            GenerateNoModel generateNoModel = await GenerateInvoiceNo(purchaseInvoiceModel.CompanyId, purchaseInvoiceModel.FinancialYearId);

            // assign values.
            Purchaseinvoice purchaseInvoice = new Purchaseinvoice();

            purchaseInvoice.InvoiceNo      = generateNoModel.VoucherNo;
            purchaseInvoice.MaxNo          = generateNoModel.MaxNo;
            purchaseInvoice.VoucherStyleId = generateNoModel.VoucherStyleId;

            purchaseInvoice.InvoiceDate           = purchaseInvoiceModel.InvoiceDate;
            purchaseInvoice.SupplierLedgerId      = purchaseInvoiceModel.SupplierLedgerId;
            purchaseInvoice.BillToAddressId       = purchaseInvoiceModel.BillToAddressId;
            purchaseInvoice.AccountLedgerId       = purchaseInvoiceModel.AccountLedgerId;
            purchaseInvoice.SupplierReferenceNo   = purchaseInvoiceModel.SupplierReferenceNo;
            purchaseInvoice.SupplierReferenceDate = purchaseInvoiceModel.SupplierReferenceDate;
            purchaseInvoice.CreditLimitDays       = purchaseInvoiceModel.CreditLimitDays;
            purchaseInvoice.PaymentTerm           = purchaseInvoiceModel.PaymentTerm;
            purchaseInvoice.Remark                = purchaseInvoiceModel.Remark;
            purchaseInvoice.TaxModelType          = purchaseInvoiceModel.TaxModelType;
            purchaseInvoice.TaxRegisterId         = purchaseInvoiceModel.TaxRegisterId;
            purchaseInvoice.CurrencyId            = purchaseInvoiceModel.CurrencyId;
            purchaseInvoice.ExchangeRate          = purchaseInvoiceModel.ExchangeRate;
            purchaseInvoice.TotalLineItemAmountFc = 0;
            purchaseInvoice.TotalLineItemAmount   = 0;
            purchaseInvoice.GrossAmountFc         = 0;
            purchaseInvoice.GrossAmount           = 0;
            purchaseInvoice.NetAmountFc           = 0;
            purchaseInvoice.NetAmount             = 0;
            purchaseInvoice.NetAmountFcinWord     = "";
            purchaseInvoice.TaxAmountFc           = 0;
            purchaseInvoice.TaxAmount             = 0;

            purchaseInvoice.DiscountPercentageOrAmount = purchaseInvoiceModel.DiscountPercentageOrAmount;
            purchaseInvoice.DiscountPerOrAmountFc      = purchaseInvoiceModel.DiscountPerOrAmountFc;
            purchaseInvoice.DiscountAmountFc           = 0;
            purchaseInvoice.DiscountAmount             = 0;

            purchaseInvoice.StatusId        = 1;//purchaseInvoiceModel.StatusId;
            purchaseInvoice.CompanyId       = purchaseInvoiceModel.CompanyId;
            purchaseInvoice.FinancialYearId = purchaseInvoiceModel.FinancialYearId;

            purchaseInvoiceId = await Create(purchaseInvoice);

            if (purchaseInvoiceId != 0)
            {
                await UpdatePurchaseInvoiceMasterAmount(purchaseInvoiceId);
            }

            return(purchaseInvoiceId); // returns.
        }
        /// <summary>
        /// update purchase invoice.
        /// </summary>
        /// <param name="purchaseInvoiceModel"></param>
        /// <returns>
        /// return true if success.
        /// </returns>
        public async Task <bool> UpdatePurchaseInvoice(PurchaseInvoiceModel purchaseInvoiceModel)
        {
            bool isUpdated = false;

            // get record.
            Purchaseinvoice purchaseInvoice = await GetByIdAsync(w => w.PurchaseInvoiceId == purchaseInvoiceModel.PurchaseInvoiceId);

            if (null != purchaseInvoice)
            {
                // assign values.
                //purchaseInvoice.PurchaseInvoiceId = purchaseInvoiceModel.PurchaseInvoiceId;
                //purchaseInvoice.InvoiceNo = purchaseInvoiceModel.InvoiceNo;
                purchaseInvoice.InvoiceDate           = purchaseInvoiceModel.InvoiceDate;
                purchaseInvoice.SupplierLedgerId      = purchaseInvoiceModel.SupplierLedgerId;
                purchaseInvoice.BillToAddressId       = purchaseInvoiceModel.BillToAddressId;
                purchaseInvoice.AccountLedgerId       = purchaseInvoiceModel.AccountLedgerId;
                purchaseInvoice.SupplierReferenceNo   = purchaseInvoiceModel.SupplierReferenceNo;
                purchaseInvoice.SupplierReferenceDate = purchaseInvoiceModel.SupplierReferenceDate;
                purchaseInvoice.CreditLimitDays       = purchaseInvoiceModel.CreditLimitDays;
                purchaseInvoice.PaymentTerm           = purchaseInvoiceModel.PaymentTerm;
                purchaseInvoice.Remark        = purchaseInvoiceModel.Remark;
                purchaseInvoice.TaxModelType  = purchaseInvoiceModel.TaxModelType;
                purchaseInvoice.TaxRegisterId = purchaseInvoiceModel.TaxRegisterId;
                purchaseInvoice.CurrencyId    = purchaseInvoiceModel.CurrencyId;
                purchaseInvoice.ExchangeRate  = purchaseInvoiceModel.ExchangeRate;

                purchaseInvoice.TotalLineItemAmountFc = 0;
                purchaseInvoice.TotalLineItemAmount   = 0;
                purchaseInvoice.GrossAmountFc         = 0;
                purchaseInvoice.GrossAmount           = 0;
                purchaseInvoice.NetAmountFc           = 0;
                purchaseInvoice.NetAmount             = 0;
                purchaseInvoice.NetAmountFcinWord     = "";
                purchaseInvoice.TaxAmountFc           = 0;
                purchaseInvoice.TaxAmount             = 0;

                purchaseInvoice.DiscountPercentageOrAmount = purchaseInvoiceModel.DiscountPercentageOrAmount;
                purchaseInvoice.DiscountPerOrAmountFc      = purchaseInvoiceModel.DiscountPerOrAmountFc;

                purchaseInvoice.DiscountAmountFc = 0;
                purchaseInvoice.DiscountAmount   = 0;

                isUpdated = await Update(purchaseInvoice);
            }

            if (isUpdated != false)
            {
                await UpdatePurchaseInvoiceMasterAmount(purchaseInvoice.PurchaseInvoiceId);
            }

            return(isUpdated); // returns.
        }
        /// <summary>
        /// get purchase invoice based on invoiceId
        /// </summary>
        /// <returns>
        /// return record.
        /// </returns>
        public async Task <PurchaseInvoiceModel> GetPurchaseInvoiceById(int invoiceId)
        {
            PurchaseInvoiceModel purchaseInvoiceModel = null;

            IList <PurchaseInvoiceModel> purchaseInvoiceModelList = await GetPurchaseInvoiceList(invoiceId);

            if (null != purchaseInvoiceModelList && purchaseInvoiceModelList.Any())
            {
                purchaseInvoiceModel = purchaseInvoiceModelList.FirstOrDefault();
            }

            return(purchaseInvoiceModel); // returns.
        }
        /// <summary>
        /// Selects the desired purchase invoice, sends it to the requesting form and closes the current form
        /// </summary>
        private void SelectPurchaseInvoice()
        {
            if (POrderContentDataGridView.CurrentCell != null)
            {
                PurchaseInvoiceModel selectedDocument = (PurchaseInvoiceModel)(POrderContentDataGridView.Rows[POrderContentDataGridView.CurrentCell.RowIndex].DataBoundItem);

                if (selectedDocument != null)
                {
                    callingForm.DocumentSelected(RequestedDocument, null, selectedDocument);
                    this.Close();
                }
            }
        }
Esempio n. 10
0
        public PurchaseInvoiceModel UpdatePurchaseInvoice(PurchaseInvoiceModel model)
        {
            var purchaseInvoice = ApplyChanges(model, false);

            purchaseInvoice.ObjectState = ObjectState.Modified;
            purchaseInvoice.UpdatedBy   = _principal.Id;
            purchaseInvoice.UpdatedDate = DateTime.Now;
            model.UpdatedBy             = purchaseInvoice.UpdatedBy.Value;
            model.UpdatedDate           = DateTime.Now;

            _purchaseInvoiceService.Update(purchaseInvoice);

            return(model);
        }
Esempio n. 11
0
        public PurchaseInvoiceModel GetPurchaseInvoiceFoodMenuById(long purchaseInvoiceId)
        {
            PurchaseInvoiceModel purchaseModel = new PurchaseInvoiceModel();

            var model = (from purchase in _iPurchaseInvoiceRepository.GetPurchaseInvoiceFoodMenuById(purchaseInvoiceId).ToList()
                         select new PurchaseInvoiceModel()
            {
                Id = purchase.Id,
                PurchaseId = purchase.PurchaseId,
                ReferenceNo = purchase.ReferenceNo,
                SupplierId = purchase.SupplierId,
                EmployeeId = purchase.EmployeeId,
                StoreId = purchase.StoreId,
                PurchaseInvoiceDate = purchase.PurchaseInvoiceDate,
                GrossAmount = purchase.GrossAmount,
                TaxAmount = purchase.TaxAmount,
                TotalAmount = purchase.TotalAmount,
                PaidAmount = purchase.PaidAmount,
                DueAmount = purchase.DueAmount,
                DeliveryNoteNumber = purchase.DeliveryNoteNumber,
                DeliveryDate = purchase.DeliveryDate,
                DriverName = purchase.DriverName,
                VehicleNumber = purchase.VehicleNumber,
                Notes = purchase.Notes,
                POReferenceNo = purchase.POReferenceNo,
                PODate = purchase.PODate
            }).SingleOrDefault();

            if (model != null)
            {
                model.purchaseInvoiceDetails = (from purchasedetails in _iPurchaseInvoiceRepository.GetPurchaseInvoiceFoodMenuDetails(purchaseInvoiceId)
                                                select new PurchaseInvoiceDetailModel()
                {
                    PurchaseInvoiceId = purchasedetails.PurchaseInvoiceId,
                    IngredientId = purchasedetails.IngredientId,
                    FoodMenuId = purchasedetails.FoodMenuId,
                    POQTY = purchasedetails.POQTY,
                    InvoiceQty = purchasedetails.InvoiceQty,
                    UnitPrice = purchasedetails.UnitPrice,
                    GrossAmount = purchasedetails.GrossAmount,
                    DiscountPercentage = purchasedetails.DiscountPercentage,
                    DiscountAmount = purchasedetails.DiscountAmount,
                    TaxAmount = purchasedetails.TaxAmount,
                    TotalAmount = purchasedetails.TotalAmount,
                    IngredientName = purchasedetails.IngredientName,
                    FoodMenuName = purchasedetails.FoodMenuName
                }).ToList();
            }
            return(model);
        }
Esempio n. 12
0
        public async Task <int> CreatePurchaseInvoiceTax(PurchaseInvoiceTaxModel purchaseInvoiceTaxModel)
        {
            int purchaseInvoiceTaxId = 0;
            int multiplier           = 1;

            // assign values.
            PurchaseInvoiceModel purchaseInvoiceModel = null;

            purchaseInvoiceModel = await purchaseInvoice.GetPurchaseInvoiceById((int)purchaseInvoiceTaxModel.PurchaseInvoiceId);

            Purchaseinvoicetax purchaseInvoiceTax = new Purchaseinvoicetax();

            purchaseInvoiceTax.PurchaseInvoiceId = purchaseInvoiceTaxModel.PurchaseInvoiceId;
            purchaseInvoiceTax.SrNo                  = purchaseInvoiceTaxModel.SrNo;
            purchaseInvoiceTax.TaxLedgerId           = purchaseInvoiceTaxModel.TaxLedgerId;
            purchaseInvoiceTax.TaxPercentageOrAmount = purchaseInvoiceTaxModel.TaxPercentageOrAmount;
            purchaseInvoiceTax.TaxPerOrAmountFc      = purchaseInvoiceTaxModel.TaxPerOrAmountFc;

            if (DiscountType.Percentage.ToString() == purchaseInvoiceTax.TaxPercentageOrAmount)
            {
                purchaseInvoiceTaxModel.TaxAmountFc = (purchaseInvoiceModel.GrossAmountFc * purchaseInvoiceTaxModel.TaxPerOrAmountFc) / 100;
            }
            else
            {
                purchaseInvoiceTaxModel.TaxAmountFc = purchaseInvoiceTaxModel.TaxPerOrAmountFc;
            }

            if (TaxAddOrDeduct.Deduct.ToString() == purchaseInvoiceTaxModel.TaxAddOrDeduct)
            {
                multiplier = -1;
            }

            purchaseInvoiceTax.TaxAddOrDeduct = purchaseInvoiceTaxModel.TaxAddOrDeduct;
            purchaseInvoiceTax.TaxAmountFc    = multiplier * purchaseInvoiceTaxModel.TaxAmountFc;
            purchaseInvoiceTax.TaxAmount      = multiplier * purchaseInvoiceTaxModel.TaxAmount;
            purchaseInvoiceTax.Remark         = purchaseInvoiceTaxModel.Remark;

            purchaseInvoiceTaxId = await Create(purchaseInvoiceTax);

            if (purchaseInvoiceTaxId != 0)
            {
                await purchaseInvoice.UpdatePurchaseInvoiceMasterAmount(purchaseInvoiceTaxId);
            }

            return(purchaseInvoiceTaxId); // returns.
        }
Esempio n. 13
0
        private string ValidationPurchaseInvoice(PurchaseInvoiceModel purchaseModel)
        {
            string ErrorString = string.Empty;

            if (string.IsNullOrEmpty(purchaseModel.SupplierId.ToString()) || purchaseModel.SupplierId == 0)
            {
                ErrorString = _locService.GetLocalizedHtmlString("ValidSupplier");
                return(ErrorString);
            }
            if (purchaseModel.purchaseInvoiceDetails == null || purchaseModel.purchaseInvoiceDetails.Count < 1)
            {
                ErrorString = _locService.GetLocalizedHtmlString("ValidPurchaseInvoiceDetails");
                return(ErrorString);
            }

            return(ErrorString);
        }
Esempio n. 14
0
        public PurchaseInvoiceModel CreatePurchaseInvoice(PurchaseInvoiceModel model)
        {
            var purchaseInvoice = ApplyChanges(model, true);

            model.ServerCode            = _serverCode;
            purchaseInvoice.ObjectState = ObjectState.Added;

            purchaseInvoice.CreatedBy   = _principal.Id;
            purchaseInvoice.CreatedDate = DateTime.Now;
            model.PurchaseInvoiceID     = purchaseInvoice.PurchaseInvoiceID;
            model.UpdatedBy             = _principal.Id;
            model.UpdatedDate           = DateTime.Now;

            purchaseInvoice.CreatedDate = DateTime.Now;

            _purchaseInvoiceService.Insert(purchaseInvoice);

            return(model);
        }
Esempio n. 15
0
        private void SaveInvoice_Click(object sender, EventArgs e)
        {
            sqlConnection = new System.Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings["connString"].ConnectionString);
            SqlCommand sqlCommand = new SqlCommand("InsertintoPurchaseInvoice", sqlConnection);

            sqlCommand.CommandType = CommandType.StoredProcedure;
            sqlConnection.Open();
            PurchaseInvoiceModel purchaseProvider = new PurchaseInvoiceModel();

            purchaseProvider.Bill_No      = Convert.ToInt32(Billnotextbox.Text);
            purchaseProvider.Invoice_No   = Convert.ToInt32(Invnotextbox.Text);
            purchaseProvider.Vendor       = VendorcomboBox.SelectedItem.ToString();
            purchaseProvider.Date         = Convert.ToDateTime(dateTimePicker1.Text);
            purchaseProvider.Item         = itemtextbox.Text;
            purchaseProvider.Quantity     = Convert.ToInt32(qtytextbox.Text);
            purchaseProvider.Shape        = shapetextbox.Text;
            purchaseProvider.Unit_Price   = Convert.ToInt32(pricetextbox.Text);
            purchaseProvider.Basic_Price  = Convert.ToInt32(BasicPrice_textbox.Text);
            purchaseProvider.GST          = Convert.ToInt32(gsttextbox.Text);
            purchaseProvider.Total_Amount = Convert.ToInt32(totalamttextbox.Text);
            sqlCommand.Parameters.AddWithValue("@billno", purchaseProvider.Bill_No);
            sqlCommand.Parameters.AddWithValue("@invoiceno", purchaseProvider.Invoice_No);
            sqlCommand.Parameters.AddWithValue("@vendor", purchaseProvider.Vendor);
            sqlCommand.Parameters.AddWithValue("@date", purchaseProvider.Date);
            sqlCommand.Parameters.AddWithValue("@item", purchaseProvider.Item);
            sqlCommand.Parameters.AddWithValue("@qty", purchaseProvider.Quantity);
            sqlCommand.Parameters.AddWithValue("@shape", purchaseProvider.Shape);
            sqlCommand.Parameters.AddWithValue("@price", purchaseProvider.Unit_Price);
            sqlCommand.Parameters.AddWithValue("@basic_amt", purchaseProvider.Basic_Price);
            sqlCommand.Parameters.AddWithValue("@gst", purchaseProvider.GST);
            sqlCommand.Parameters.AddWithValue("@totalamt", purchaseProvider.Total_Amount);
            int i = sqlCommand.ExecuteNonQuery();

            if (i != 0)
            {
                MessageBox.Show("Successfully Saved!!");
            }
        }
Esempio n. 16
0
        // Calculate EntryDetails using Models Case Update
        public static List <EntryDetailModel> UpdateCalculateEntries(int portofolioaccount, int EntryID, SellingInvoiceModel sellingInvoiceModel = null,
                                                                     PurchaseInvoiceModel purchaseInvoiceModel = null, ReceiptExchangeModel receiptExchangeModel = null,
                                                                     NoticeModel noticeModel = null)
        {
            #region Definitions
            decimal TotalNet = 0, TotalBankCommision = 0, TotalTaxOnCommision = 0, TotalSTocksSales = 0, TotalSTocksPurchase = 0;
            List <EntryDetailModel> DetailListModel = new List <EntryDetailModel>();
            int        AccBankCommision = 0, AccTaxonCommision = 0, AccSalesStocks = 0, AccPuchaseStocks = 0;
            EntryModel Entrymodel = new EntryModel();

            #endregion
            #region SellingInvoice
            if (sellingInvoiceModel != null)
            {
                var SettingAccsell = sellingInvoiceModel.SettingModel.SettingAccs;
                var SellDetails    = sellingInvoiceModel.DetailsModels;
                //Get EntryDetail Accounts From Setting
                #region SettingAccounts
                foreach (var Accs in SettingAccsell)
                {
                    if (Accs.AccountType == 1)
                    {
                        AccBankCommision = Accs.AccountID;
                    }
                    else if (Accs.AccountType == 2)
                    {
                        AccTaxonCommision = Accs.AccountID;
                    }
                    else
                    {
                        AccSalesStocks = Accs.AccountID;
                    }
                }
                #endregion

                #region Calculate EntryDetailsValues
                if (SellDetails != null)
                {
                    foreach (var item in SellDetails)
                    {
                        TotalNet            += item.NetAmmount;
                        TotalBankCommision  += item.BankCommission;
                        TotalTaxOnCommision += item.TaxOnCommission;
                        TotalSTocksSales    += item.SelingValue;
                    }
                }
                #endregion


                #region EntryDetails
                //Add Debit Accounts with values
                #region Debit
                EntryDetailModel DetailModel1 = new EntryDetailModel();
                DetailModel1.Debit     = TotalNet;
                DetailModel1.AccountID = portofolioaccount;
                DetailModel1.EntryID   = EntryID;
                DetailListModel.Add(DetailModel1);
                EntryDetailModel DetailModel2 = new EntryDetailModel();
                DetailModel2.Debit     = TotalBankCommision;
                DetailModel2.AccountID = AccBankCommision;
                DetailModel1.EntryID   = EntryID;
                DetailListModel.Add(DetailModel2);
                EntryDetailModel DetailModel3 = new EntryDetailModel();
                DetailModel3.Debit     = TotalTaxOnCommision;
                DetailModel3.AccountID = AccTaxonCommision;
                DetailModel1.EntryID   = EntryID;
                DetailListModel.Add(DetailModel3);
                #endregion

                //Add Credit Accounts with values
                #region Credit
                EntryDetailModel DetailModel4 = new EntryDetailModel();
                DetailModel4.Credit    = TotalSTocksSales;
                DetailModel4.AccountID = AccSalesStocks;
                DetailModel1.EntryID   = EntryID;
                DetailListModel.Add(DetailModel4);
                #endregion

                #endregion
            }
            #endregion
            #region PurchaseInvoice
            if (purchaseInvoiceModel != null)
            {
                var SettingAccpurchase = purchaseInvoiceModel.SettingModel.SettingAccs;
                var PurchaseDetails    = purchaseInvoiceModel.DetailsModels;
                //Get EntryDetail Accounts From Setting
                #region SettingAccounts
                foreach (var Accs in SettingAccpurchase)
                {
                    if (Accs.AccountType == 1)
                    {
                        AccPuchaseStocks = Accs.AccountID;
                    }
                    else if (Accs.AccountType == 2)
                    {
                        AccBankCommision = Accs.AccountID;
                    }
                    else
                    {
                        AccTaxonCommision = Accs.AccountID;
                    }
                }
                #endregion

                #region Calculate EntryDetailsValues
                if (PurchaseDetails != null)
                {
                    foreach (var item in PurchaseDetails)
                    {
                        TotalNet            += item.NetAmmount;
                        TotalBankCommision  += item.BankCommission;
                        TotalTaxOnCommision += item.TaxOnCommission;
                        TotalSTocksPurchase += item.PurchaseValue;
                    }
                }
                #endregion



                #region EntryDetails
                //Add Debit Accounts with values
                #region Debit
                EntryDetailModel DetailModel1 = new EntryDetailModel();
                DetailModel1.Debit     = TotalNet;
                DetailModel1.AccountID = AccPuchaseStocks;
                DetailModel1.EntryID   = EntryID;
                DetailListModel.Add(DetailModel1);
                EntryDetailModel DetailModel2 = new EntryDetailModel();
                DetailModel2.Debit     = TotalBankCommision;
                DetailModel2.AccountID = AccBankCommision;
                DetailModel1.EntryID   = EntryID;
                DetailListModel.Add(DetailModel2);
                EntryDetailModel DetailModel3 = new EntryDetailModel();
                DetailModel3.Debit     = TotalTaxOnCommision;
                DetailModel3.AccountID = AccTaxonCommision;
                DetailModel1.EntryID   = EntryID;
                DetailListModel.Add(DetailModel3);
                #endregion

                //Add Credit Accounts with values
                #region Credit

                EntryDetailModel DetailModel4 = new EntryDetailModel();
                DetailModel4.Credit    = TotalSTocksPurchase;
                DetailModel4.AccountID = portofolioaccount;
                DetailModel4.EntryID   = EntryID;
                DetailListModel.Add(DetailModel4);
                #endregion

                #endregion
            }
            #endregion
            #region ReceiptExchange
            if (receiptExchangeModel != null)
            {
                #region ReceiptExchange


                var ReceiptExchangeDetails = receiptExchangeModel.RecExcDetails;


                #region EntryDetails
                if (ReceiptExchangeDetails != null)
                {
                    foreach (var item in ReceiptExchangeDetails)
                    {
                        if (item.Debit != null)
                        {
                            //Add Debit Accounts with values
                            #region Debit
                            EntryDetailModel DetailModel = new EntryDetailModel();
                            DetailModel.Debit     = item.Debit;
                            DetailModel.AccountID = item.AccountID;
                            DetailModel.EntryID   = EntryID;
                            DetailListModel.Add(DetailModel);
                            #endregion
                        }
                        if (item.Credit != null)
                        {
                            //Add Credit Accounts with values
                            #region Credit
                            EntryDetailModel DetailModel = new EntryDetailModel();
                            DetailModel.Credit    = item.Credit;
                            DetailModel.AccountID = item.AccountID;
                            DetailModel.EntryID   = EntryID;
                            DetailListModel.Add(DetailModel);
                            #endregion
                        }
                    }
                }

                #endregion

                #endregion
            }
            #endregion
            #region NoticeDebitCredit
            if (noticeModel != null)
            {
                #region DebitCredit


                var NoticeDetails = noticeModel.NoticeModelDetails;


                #region EntryDetails
                if (NoticeDetails != null)
                {
                    foreach (var item in NoticeDetails)
                    {
                        if (item.Debit != null || item.StocksDebit != null)
                        {
                            //Add Debit Accounts with values
                            #region Debit
                            EntryDetailModel DetailModel = new EntryDetailModel();
                            DetailModel.Debit = item.Debit;
                            if (item.StocksDebit != null)
                            {
                                DetailModel.StocksDebit = item.StocksDebit;
                            }
                            DetailModel.AccountID = item.AccountID;
                            DetailModel.EntryID   = EntryID;
                            DetailListModel.Add(DetailModel);
                            #endregion
                        }
                        if (item.Credit != null || item.StocksCredit != null)
                        {
                            //Add Credit Accounts with values
                            #region Credit
                            EntryDetailModel DetailModel = new EntryDetailModel();
                            DetailModel.Credit = item.Credit;
                            if (item.StocksCredit != null)
                            {
                                DetailModel.StocksCredit = item.StocksCredit;
                            }
                            DetailModel.AccountID = item.AccountID;
                            DetailModel.EntryID   = EntryID;
                            DetailListModel.Add(DetailModel);
                            #endregion
                        }
                    }
                }

                #endregion

                #endregion
            }
            #endregion
            return(DetailListModel);
        }
Esempio n. 17
0
 public int InsertPurchaseInvoice(PurchaseInvoiceModel purchaseModel)
 {
     return(_iPurchaseInvoiceRepository.InsertPurchaseInvoice(purchaseModel));
 }
Esempio n. 18
0
 public int UpdatePurchaseInvoice(PurchaseInvoiceModel purchaseModel)
 {
     return(_iPurchaseInvoiceRepository.UpdatePurchaseInvoice(purchaseModel));
 }
        public IActionResult Search(int TableNum, string Code)
        {
            switch (TableNum)
            {
                #region Purchase Invoice
            case 1:
                var PurchaseInvoiceEntitylist = unitOfWork.PurchaseInvoiceRepository.Get(filter: a => a.Code == Code).SingleOrDefault();
                if (PurchaseInvoiceEntitylist != null)
                {
                    PurchaseInvoiceModel purchaseInvoiceModel = new PurchaseInvoiceModel();
                    purchaseInvoiceModel.Code         = PurchaseInvoiceEntitylist.Code;
                    purchaseInvoiceModel.PurchaseDate = PurchaseInvoiceEntitylist.Date.Value.ToString("d/M/yyyy");

                    purchaseInvoiceModel.PurchaseDateHijri = DateHelper.GetHijriDate(PurchaseInvoiceEntitylist.Date);

                    //var EmplyeeEntity = unitOfWork.EmployeeRepository.Get(filter: e => e.EmployeeID == purchaseInvoiceModel.EmployeeID).SingleOrDefault();
                    //purchaseInvoiceModel.EmpCode = EmplyeeEntity.Code;
                    //purchaseInvoiceModel.EmpNameAR = EmplyeeEntity.NameAR;
                    //purchaseInvoiceModel.EmpNameEN = EmplyeeEntity.NameEN;
                    purchaseInvoiceModel.EmployeeID = PurchaseInvoiceEntitylist.EmployeeID;
                    purchaseInvoiceModel.EmpNameAR  = PurchaseInvoiceEntitylist.Employee.NameAR;
                    purchaseInvoiceModel.EmpCode    = PurchaseInvoiceEntitylist.Employee.Code;


                    var id = unitOfWork.PurchaseOrderRepository.GetEntity(filter: a => a.PurchaseOrderID == PurchaseInvoiceEntitylist.PurchaseOrderID).PortfolioID;
                    var PortfolioEntity = unitOfWork.PortfolioRepository.GetEntity(filter: p => p.PortfolioID == id);
                    purchaseInvoiceModel.PortfolioCode   = PortfolioEntity.Code;
                    purchaseInvoiceModel.PortfolioNameAR = PortfolioEntity.NameAR;
                    purchaseInvoiceModel.PortfolioNameEN = PortfolioEntity.NameEN;

                    purchaseInvoiceModel.PortfolioAccount = unitOfWork.PortfolioAccountRepository.GetEntity(filter: s => s.PortfolioID == id).AccountID;

                    purchaseInvoiceModel.DetailsModels = unitOfWork.PurchaseInvoiceDetailRepository.Get(filter: z => z.PurchaseInvoiceID == PurchaseInvoiceEntitylist.PurchaseInvoiceID).Select(a => new PurchaseInvoiceDetailModel {
                        BankCommission          = a.BankCommission,
                        BankCommissionRate      = a.BankCommissionRate,
                        NetAmmount              = a.NetAmmount,
                        PartnerCode             = a.Partner.Code,
                        PartnerID               = a.PartnerID,
                        PartnerNameAR           = a.Partner.NameAR,
                        PartnerNameEN           = a.Partner.NameEN,
                        PurchaseInvoiceDetailID = a.PurchaseInvoiceDetailID,
                        PurchaseInvoiceID       = a.PurchaseInvoiceID,
                        PurchasePrice           = a.PurchasePrice,
                        PurchaseValue           = a.PurchaseValue,
                        StockCount              = a.StockCount,
                        TaxOnCommission         = a.TaxOnCommission,
                        TaxRateOnCommission     = a.TaxRateOnCommission,
                    });
                    decimal?oldNetAmmount = 0.0m;
                    foreach (var item in purchaseInvoiceModel.DetailsModels)
                    {
                        oldNetAmmount += item.NetAmmount;
                    }

                    purchaseInvoiceModel.newRialBalance  = _stocksHelper.RialBalancUpdate(PurchaseInvoiceEntitylist.PurchaseOrder.PortfolioID, oldNetAmmount);
                    purchaseInvoiceModel.PurchaseOrderID = PurchaseInvoiceEntitylist.PurchaseOrderID;


                    purchaseInvoiceModel.SettingModel = GetSetting(2);

                    var EntryPurchaseInvoiceEntitylist = unitOfWork.EntryRepository.Get(filter: a => a.PurchaseInvoiceID == purchaseInvoiceModel.PurchaseInvoiceID);
                    purchaseInvoiceModel.EntryModel = _mapper.Map <EntryModel>(EntryPurchaseInvoiceEntitylist.SingleOrDefault());
                    if (EntryPurchaseInvoiceEntitylist.Count() > 0)
                    {
                        var EntryDitailsPurchaseInvoiceEntitylist = unitOfWork.EntryDetailRepository.Get(filter: d => d.EntryID == purchaseInvoiceModel.EntryModel.EntryID);
                        purchaseInvoiceModel.EntryModel.EntryDetailModel = _mapper.Map <IEnumerable <EntryDetailModel> >(EntryDitailsPurchaseInvoiceEntitylist);
                    }

                    return(Ok(purchaseInvoiceModel));
                }
                else
                {
                    return(Ok(0));
                }


                #endregion

                #region selling Invoice
            case 2:
                var SellingInvoiceEntitylist = unitOfWork.SellingInvoiceReposetory.Get(NoTrack: "NoTrack", filter: a => a.Code == Code).SingleOrDefault();
                if (SellingInvoiceEntitylist.Code != null)
                {
                    SellingInvoiceModel SellingInvoiceModel = new SellingInvoiceModel();
                    SellingInvoiceModel = _mapper.Map <SellingInvoiceModel>(SellingInvoiceEntitylist);

                    SellingInvoiceModel.SellDate      = SellingInvoiceEntitylist.Date.Value.ToString("d/M/yyyy");
                    SellingInvoiceModel.SellDateHijri = DateHelper.GetHijriDate(SellingInvoiceEntitylist.Date);

                    var EmplyeeEntity = unitOfWork.EmployeeRepository.Get(filter: e => e.EmployeeID == SellingInvoiceModel.EmployeeID).SingleOrDefault();
                    SellingInvoiceModel.EmpCode   = EmplyeeEntity.Code;
                    SellingInvoiceModel.EmpNameAR = EmplyeeEntity.NameAR;
                    SellingInvoiceModel.EmpCode   = EmplyeeEntity.NameEN;
                    var id = unitOfWork.SellingOrderRepository.GetEntity(filter: x => x.SellingOrderID == SellingInvoiceEntitylist.SellingOrderID).PortfolioID;
                    var PortfolioEntity = unitOfWork.PortfolioRepository.Get(filter: p => p.PortfolioID == id).SingleOrDefault();
                    SellingInvoiceModel.PortfolioCode   = PortfolioEntity.Code;
                    SellingInvoiceModel.PortfolioNameAR = PortfolioEntity.NameAR;
                    SellingInvoiceModel.PortfolioNameEN = PortfolioEntity.NameEN;

                    SellingInvoiceModel.PortfolioAccount = unitOfWork.PortfolioAccountRepository.GetEntity(filter: s => s.PortfolioID == id).AccountID;

                    SellingInvoiceModel.DetailsModels = unitOfWork.SellingInvoiceDetailRepository.Get(filter: z => z.SellingInvoiceID == SellingInvoiceEntitylist.SellingInvoiceID).Select(a => new SellingInvoiceDetailsModel {
                        BankCommission         = a.BankCommission,
                        BankCommissionRate     = a.BankCommissionRate,
                        NetAmmount             = a.NetAmmount,
                        PartnerCode            = a.Partner.Code,
                        PartnerID              = a.PartnerID,
                        PartnerNameAR          = a.Partner.NameAR,
                        PartnerNameEN          = a.Partner.NameEN,
                        SelingValue            = a.SelingValue,
                        SellingInvoiceDetailID = a.SellInvoiceDetailID,
                        SellingInvoiceID       = a.SellingInvoiceID,
                        SellingPrice           = a.SellingPrice,
                        StockCount             = a.StockCount,
                        StocksCount            = a.StockCount,
                        TaxRateOnCommission    = a.TaxRateOnCommission,
                        TaxOnCommission        = a.TaxOnCommission,
                    });


                    SellingInvoiceModel.SettingModel = GetSetting(1);


                    var EntrySellingInvoiceEntitylist = unitOfWork.EntryRepository.Get(filter: a => a.SellingInvoiceID == SellingInvoiceModel.SellingInvoiceID);
                    SellingInvoiceModel.EntryModel = _mapper.Map <EntryModel>(EntrySellingInvoiceEntitylist.SingleOrDefault());
                    if (EntrySellingInvoiceEntitylist.Count() > 0)
                    {
                        var EntryDitailsSellingInvoiceEntitylist = unitOfWork.EntryDetailRepository.Get(filter: d => d.EntryID == SellingInvoiceModel.EntryModel.EntryID);
                        SellingInvoiceModel.EntryModel.EntryDetailModel = _mapper.Map <IEnumerable <EntryDetailModel> >(EntryDitailsSellingInvoiceEntitylist);
                    }
                    return(Ok(SellingInvoiceModel));
                }
                else
                {
                    return(Ok(0));
                }
                #endregion



                #region Notice Creditor
            case 3:
                var NoticeCreditorEntityList = unitOfWork.NoticeRepository.Get(filter: a => a.Code == Code && a.Type == false);
                if (NoticeCreditorEntityList.Count() > 0)
                {
                    NoticeModel noticeModel = new NoticeModel();
                    noticeModel = GetNotice(NoticeCreditorEntityList.SingleOrDefault(), false);
                    return(Ok(noticeModel));
                }
                else
                {
                    return(Ok(0));
                }
                #endregion

                #region Notice Debitor
            case 4:
                var NoticeDebitorEntityList = unitOfWork.NoticeRepository.Get(filter: a => a.Code == Code && a.Type == true);
                if (NoticeDebitorEntityList.Count() > 0)
                {
                    NoticeModel noticeModel = new NoticeModel();
                    noticeModel = GetNotice(NoticeDebitorEntityList.SingleOrDefault(), true);
                    return(Ok(noticeModel));
                }
                else
                {
                    return(Ok(0));
                }
                #endregion

                #region  Receipt voucher Ryal
            case 5:
            {
                var ReceiptExchangeEntitylist = unitOfWork.ReceiptExchangeRepository.GetEntity(filter: x => x.Code == Code && x.Type == false && x.ReceiptExchangeType == true);
                if (ReceiptExchangeEntitylist != null)
                {
                    ReceiptExchangeModel receiptExchangeModel = new ReceiptExchangeModel();
                    receiptExchangeModel = GetReceiptExchange(ReceiptExchangeEntitylist, 5);
                    return(Ok(receiptExchangeModel));
                }
                else
                {
                    return(Ok(0));
                }
            }
                #endregion

                #region  Receipt voucher chique
            case 6:
            {
                var ReceiptExchangeEntitylist = unitOfWork.ReceiptExchangeRepository.Get(filter: x => x.Code == Code && x.Type == false && x.ReceiptExchangeType == false).FirstOrDefault();
                if (ReceiptExchangeEntitylist != null)
                {
                    ReceiptExchangeModel receiptExchangeModel = new ReceiptExchangeModel();
                    receiptExchangeModel = GetReceiptExchange(ReceiptExchangeEntitylist, 5);
                    return(Ok(receiptExchangeModel));
                }
                else
                {
                    return(Ok(0));
                }
            }
                #endregion


                #region  Exchange voucher Ryal
            case 7:
            {
                var ReceiptExchangeEntitylist = unitOfWork.ReceiptExchangeRepository.Get(filter: x => x.Code == Code && x.ReceiptExchangeType == true && x.Type == true);
                if (ReceiptExchangeEntitylist.Count() > 0)
                {
                    ReceiptExchangeModel receiptExchangeModel = new ReceiptExchangeModel();
                    receiptExchangeModel = GetReceiptExchange(ReceiptExchangeEntitylist.SingleOrDefault(), 6);
                    return(Ok(receiptExchangeModel));
                }
                else
                {
                    return(Ok(0));
                }
            }
                #endregion

                #region  Exchange voucher chique
            case 8:
            {
                var ReceiptExchangeEntitylist = unitOfWork.ReceiptExchangeRepository.GetEntity(filter: x => x.Code == Code && x.Type == true && x.ReceiptExchangeType == false);
                if (ReceiptExchangeEntitylist != null)
                {
                    ReceiptExchangeModel receiptExchangeModel = new ReceiptExchangeModel();
                    receiptExchangeModel = GetReceiptExchange(ReceiptExchangeEntitylist, 6);
                    return(Ok(receiptExchangeModel));
                }
                else
                {
                    return(Ok(0));
                }
            }
                #endregion

                #region Country
            case 9:
            {
                var CountryEntityList = unitOfWork.CountryRepository.Get(filter: x => x.Code == Code || x.NameAR == Code);
                if (CountryEntityList.Count() > 0)
                {
                    CountryModel countryModel = _mapper.Map <CountryModel>(CountryEntityList.SingleOrDefault());
                    return(Ok(countryModel));
                }
                else
                {
                    return(Ok(0));
                }
            }
                #endregion


                #region Account
            case 10:
            {
                var AccountEntityList = unitOfWork.AccountRepository.Get(filter: x => x.Code == Code || x.NameAR == Code);
                if (AccountEntityList.Count() > 0)
                {
                    AccountModel AccountModel = _mapper.Map <AccountModel>(AccountEntityList.SingleOrDefault());
                    return(Ok(AccountModel));
                }
                else
                {
                    return(Ok(0));
                }
            }

                #endregion
                #region Employee
            case 11:
            {
                var EmployeeEntityList = unitOfWork.EmployeeRepository.GetEntity(filter: x => x.Code == Code);
                if (EmployeeEntityList != null)
                {
                    string        date          = EmployeeEntityList.BirthDate.Value.ToString("d/M/yyyy");
                    EmployeeModel EmployeeModel = _mapper.Map <EmployeeModel>(EmployeeEntityList);
                    EmployeeModel.BirthDate = date;
                    var EmployCardsEntityList = unitOfWork.EmployeeCardRepository.Get(filter: x => x.EmployeeID == EmployeeModel.EmployeeID);
                    EmployeeModel.emplCards = _mapper.Map <IEnumerable <EmployeeCardModel> >(EmployCardsEntityList);
                    return(Ok(EmployeeModel));
                }
                else
                {
                    return(Ok(0));
                }
            }
                #endregion

                #region Partner
            case 12:
            {
                var PartnerEntityList = unitOfWork.PartnerRepository.Get(filter: x => x.Code == Code).SingleOrDefault();
                if (PartnerEntityList != null)
                {
                    string        date         = PartnerEntityList.Date.ToString("d/M/yyyy");
                    string        IssueDate    = PartnerEntityList.IssueDate.Value.ToString("d/M/yyyy");
                    PartenerModel partnerModel = _mapper.Map <PartenerModel>(PartnerEntityList);
                    partnerModel.Date      = date;
                    partnerModel.IssueDate = IssueDate;
                    var Countries = unitOfWork.CountryRepository.Get(filter: x => x.CountryID == partnerModel.CountryID);
                    partnerModel.Countries = _mapper.Map <IEnumerable <CountryModel> >(Countries);
                    IEnumerable <PortfolioTransaction> StocksCountList = unitOfWork.PortfolioTransactionsRepository.Get(filter: x => x.PartnerID == partnerModel.PartnerID);
                    partnerModel.StocksCount = 0;
                    for (int ii = 0; ii < StocksCountList.Count(); ii++)
                    {
                        partnerModel.StocksCount += StocksCountList.ElementAt(ii).CurrentStocksCount;
                    }

                    return(Ok(partnerModel));
                }
                else
                {
                    return(Ok(0));
                }
            }
                #endregion

                #region portfolio
            case 13:
            {
                var PortfolioEntityList = unitOfWork.PortfolioRepository.Get(filter: x => x.Code == Code || x.NameAR == Code);
                if (PortfolioEntityList.Count() > 0)
                {
                    return(Ok(GetPortfolio(PortfolioEntityList.SingleOrDefault())));
                }
                else
                {
                    return(Ok(0));
                }
            }
                #endregion


                #region selling Order


            case 14:
            {
                var sellingorder = unitOfWork.SellingOrderRepository.Get(filter: x => x.Code == Code).SingleOrDefault();
                var model        = _mapper.Map <SellingOrderModel>(sellingorder);
                if (sellingorder != null)
                {
                    #region Date part
                    if (sellingorder.OrderDate != null)
                    {
                        model.OrderDateGorg  = sellingorder.OrderDate.ToString("d/M/yyyy");
                        model.OrderDateHigri = DateHelper.GetHijriDate(sellingorder.OrderDate);
                    }



                    #endregion

                    #region  Details
                    var Details = unitOfWork.SellingOrderDetailRepository

                                  .Get(filter: m => m.SellingOrderID == sellingorder.SellingOrderID)
                                  .Select(m => new SellingOrderDetailModel
                        {
                            PartnerID         = m.PartnerID,
                            PartnerNameAr     = m.Partner.NameAR,
                            PriceType         = m.PriceType,
                            SellingOrderID    = m.SellingOrderID,
                            SellOrderDetailID = m.SellOrderDetailID,
                            StockCount        = m.StockCount,
                            TradingValue      = m.TradingValue,
                            PartnerCode       = m.Partner.Code
                        });



                    if (Details != null)
                    {
                        model.sellingOrderDetailModels = Details;
                    }

                    #endregion
                    model.Count         = unitOfWork.SellingOrderRepository.Count();
                    model.Portfoliocode = unitOfWork.PortfolioRepository.GetEntity(filter: a => a.PortfolioID == sellingorder.PortfolioID).Code;

                    return(Ok(model));
                }
                else
                {
                    return(Ok(0));
                }
            }



                #endregion

                #region  Order


            case 15:
            {
                var Purchaseorder = unitOfWork.PurchaseOrderRepository.Get(filter: x => x.Code == Code).SingleOrDefault();
                var model         = _mapper.Map <PurchaseOrderModel>(Purchaseorder);

                #region Date part
                if (Purchaseorder.OrderDate != null)
                {
                    model.OrderDate      = Purchaseorder.OrderDate.ToString("d/M/yyyy");
                    model.OrderDateHijri = DateHelper.GetHijriDate(Purchaseorder.OrderDate);
                }



                #endregion

                #region  Details
                var Details = unitOfWork.PurchaseOrderDetailRepository

                              .Get(filter: m => m.PurchaseOrderID == Purchaseorder.PurchaseOrderID)
                              .Select(m => new PurchaseOrderDetailModel
                    {
                        PartnerID             = m.PartnerID,
                        PartnerNameAr         = m.Partner.NameAR,
                        PriceType             = m.PriceType,
                        PurchaseOrderID       = m.PurchaseOrderID,
                        PurchaseOrderDetailID = m.PurchaseOrderDetailID,
                        StockCount            = m.StockCount,
                        TradingValue          = m.TradingValue,
                        PartnerCode           = m.Partner.Code
                    });



                if (Details != null)
                {
                    model.purchaseordersDetailsModels = Details;
                }

                #endregion
                model.Count         = unitOfWork.PurchaseOrderRepository.Count();
                model.Portfoliocode = unitOfWork.PortfolioRepository.GetEntity(filter: a => a.PortfolioID == Purchaseorder.PortfolioID).Code;

                return(Ok(model));
            }



                #endregion
            }
            return(Ok("Error Table Number"));
        }
Esempio n. 20
0
        public ActionResult PurchaseInvoiceFoodMenu(PurchaseInvoiceModel purchaseModel, string Cancel)
        {
            purchaseModel.SupplierList = _iDropDownService.GetSupplierList();
            //purchaseModel.FoodMenuList = _iDropDownService.GetFoodMenuList();
            purchaseModel.StoreList    = _iDropDownService.GetStoreList();
            purchaseModel.EmployeeList = _iDropDownService.GetEmployeeList();
            string purchaseMessage = string.Empty;

            if (!ModelState.IsValid)
            {
                string errorString = this.ValidationPurchaseInvoice(purchaseModel);
                if (!string.IsNullOrEmpty(errorString))
                {
                    return(Json(new { error = true, message = errorString, status = 201 }));
                }
            }

            if (purchaseModel.purchaseInvoiceDetails != null)
            {
                if (purchaseModel.purchaseInvoiceDetails.Count > 0)
                {
                    purchaseModel.InventoryType = 1;
                    if (purchaseModel.Id > 0)
                    {
                        int result = _iPurchaseInvoiceService.UpdatePurchaseInvoiceFoodMenu(purchaseModel);
                        if (result > 0)
                        {
                            purchaseMessage = _locService.GetLocalizedHtmlString("EditSuccss");
                        }
                    }
                    else
                    {
                        purchaseModel.ReferenceNo = _iPurchaseInvoiceService.ReferenceNumberFoodMenu().ToString();
                        //purchaseModel.PurchaseInvoiceDate = DateTime.UtcNow.AddMinutes(LoginInfo.Timeoffset);

                        int result = _iPurchaseInvoiceService.InsertPurchaseInvoiceFoodMenu(purchaseModel);
                        if (result > 0)
                        {
                            purchaseMessage = _locService.GetLocalizedHtmlString("SaveSuccess") + " Reference No is: " + result.ToString();
                            //    if (purchaseModel.IsSendEmail)
                            //    {
                            //        if (!string.IsNullOrEmpty(purchaseModel.SupplierEmail))
                            //        {
                            //            //  _iEmailService.SendEmailToForFoodMenuPurchaseInvoice(purchaseModel, purchaseModel.SupplierEmail);
                            //        }
                            //    }
                        }
                    }
                }
                else
                {
                    purchaseMessage = _locService.GetLocalizedHtmlString("ValidPurchaseInvoiceDetails");
                    return(Json(new { error = true, message = purchaseMessage, status = 201 }));
                }
            }
            else
            {
                purchaseMessage = _locService.GetLocalizedHtmlString("ValidPurchaseInvoiceDetails");
                return(RedirectToAction("PurchaseInvoiceFoodMenu", "PurchaseInvoiceFoodMenu"));

                // return Json(new { error = true, message = purchaseMessage, status = 201 });
            }
            // return View(purchaseModel);
            return(Json(new { error = false, message = purchaseMessage, status = 200 }));
            //return View();
        }
Esempio n. 21
0
        private PurchaseInvoice ApplyChanges(PurchaseInvoiceModel model, bool isItANewPruchaseInvoice)
        {
            var date      = DateTime.Parse(model.PurchaseInvoiceDate);
            var addressID = _supplierDepartmentService.SupplierDepartmentById(model.SupplierDepartmentId).SupplierLocations.FirstOrDefault().AddressID;
            //    var purchaseLedgerEntryID = System.Guid.Parse("00760000-0002-0000-0006-827344180700");
            var purchaseInvoiceID = Guid.Empty != model.PurchaseInvoiceID
                ? model.PurchaseInvoiceID
                : new Guid(model.UploadFolder);
            var divisionId               = _principal.DivisionId.Value;
            var supplierDepartmentId     = model.SupplierDepartmentId;
            var purchaseInvoiceReference = model.PurchaseInvoiceReference;
            var createdDate              = DateTime.Now;
            var updatedDate              = DateTime.Now;
            var updatedBy = _principal.Id;
            var createdBy = _principal.Id;
            var isSaved   = model.IsSaved;

            // calculate the total of purchase invoice items and compare it with the Total of the purchase invoice
            PurchaseInvoice purchaseInvoice;

            if (!isItANewPruchaseInvoice)
            {
                var status = (int)PurchaseInvoiceStatus.OK;
                //this is not a new purchase invoice
                purchaseInvoice = _purchaseInvoiceService.PurchaseInvoiceById(purchaseInvoiceID);
                var totalOfItems = purchaseInvoice.PurchaseInvoiceItems.Sum(
                    purchaseInvoiceItem => purchaseInvoiceItem.TotalPrice * (purchaseInvoiceItem.PurchaseInvoiceItemQuantity ?? 0));

                if (model.SupplierInvoiceAmount != totalOfItems)
                {
                    if (purchaseInvoice.Status == (int)PurchaseInvoiceStatus.PendingQuery || purchaseInvoice.Status == (int)PurchaseInvoiceStatus.TotalAndPendingQuery)
                    {
                        status = (int)PurchaseInvoiceStatus.TotalAndPendingQuery;
                    }
                    else
                    {
                        status = (int)PurchaseInvoiceStatus.Total;
                    }
                }

                purchaseInvoice.PurchaseInvoiceReference = purchaseInvoiceReference;
                purchaseInvoice.PurchaseInvoiceDate      = date;
                purchaseInvoice.Total       = model.SupplierInvoiceAmount.Value;
                purchaseInvoice.Status      = status;
                purchaseInvoice.UpdatedDate = updatedDate;
                purchaseInvoice.UpdatedBy   = _principal.Id;

                purchaseInvoice.SupplierDepartmentID = supplierDepartmentId;
            }
            else
            {
                purchaseInvoice = new PurchaseInvoice
                {
                    PurchaseInvoiceID        = purchaseInvoiceID,
                    PurchaseInvoiceReference = purchaseInvoiceReference,
                    PurchaseInvoiceDate      = date,
                    ServerCode = _serverCode,
                    // CurrencyRate = decimal.Parse(model.CurrencyRate),
                    NoteID = null,
                    SupplierDepartmentID = supplierDepartmentId,
                    AddressID            = addressID,
                    // PurchaseLedgerEntryID = purchaseLedgerEntryID,
                    DivisionID = divisionId,

                    CreatedDate = createdDate,
                    CreatedBy   = _principal.Id,
                    UpdatedDate = updatedDate,
                    UpdatedBy   = _principal.Id,

                    Total  = model.SupplierInvoiceAmount.Value,
                    Status = 1
                };
            }

            return(purchaseInvoice);
        }
        // Add Purchase Order Stocks Count To Portofolio
        public void TransferPurchaseToStocks(PurchaseInvoiceModel purchaseInvoiceModel)
        {
            var Details = purchaseInvoiceModel.DetailsModels;

            if (unitOfWork.PortfolioTransactionsRepository.Get(filter: m => m.PortfolioID == purchaseInvoiceModel.PortfolioID).Count() != 0)
            {
                var PortofolioStocks = unitOfWork.PortfolioTransactionsRepository.Get(filter: m => m.PortfolioID == purchaseInvoiceModel.PortfolioID);

                foreach (var detail in Details)
                {
                    if (PortofolioStocks.Any(x => x.PartnerID == detail.PartnerID))
                    {
                        foreach (var item in PortofolioStocks)
                        {
                            if (detail.PartnerID == item.PartnerID)
                            {
                                item.CurrentStocksCount = item.CurrentStocksCount + detail.StockCount;
                                item.CurrentStockValue  = (((decimal)item.CurrentStocksCount * item.CurrentStockValue) +
                                                           ((decimal)detail.StockCount * detail.PurchaseValue))
                                                          / (decimal)(item.CurrentStocksCount + detail.StockCount);
                                unitOfWork.PortfolioTransactionsRepository.Update(item);
                                unitOfWork.Save();
                            }
                        }
                    }
                    else
                    {
                        foreach (var item in Details)
                        {
                            PortfolioTransactionModel portfolioTransactionModel = new PortfolioTransactionModel();
                            portfolioTransactionModel.PortfolioID        = purchaseInvoiceModel.PortfolioID;
                            portfolioTransactionModel.PartnerID          = item.PartnerID;
                            portfolioTransactionModel.PortTransID        = 0;
                            portfolioTransactionModel.CurrentStocksCount = item.StockCount;
                            portfolioTransactionModel.CurrentStockValue  = item.PurchaseValue;

                            var trancaction = _mapper.Map <PortfolioTransaction>(portfolioTransactionModel);
                            unitOfWork.PortfolioTransactionsRepository.Insert(trancaction);
                            unitOfWork.Save();
                        }
                    }
                }
            }

            else
            {
                foreach (var item in Details)
                {
                    PortfolioTransactionModel portfolioTransactionModel = new PortfolioTransactionModel();
                    portfolioTransactionModel.PortfolioID        = purchaseInvoiceModel.PortfolioID;
                    portfolioTransactionModel.PartnerID          = item.PartnerID;
                    portfolioTransactionModel.PortTransID        = 0;
                    portfolioTransactionModel.CurrentStocksCount = item.StockCount;
                    portfolioTransactionModel.CurrentStockValue  = item.PurchaseValue;

                    var trancaction = _mapper.Map <PortfolioTransaction>(portfolioTransactionModel);
                    unitOfWork.PortfolioTransactionsRepository.Insert(trancaction);
                    unitOfWork.Save();
                }
            }
        }