Exemplo n.º 1
0
        // POST: purshaseBill/Create
        // To protect from overposting attacks, please enable the specific properties you want to bind to, for
        // more details see http://go.microsoft.com/fwlink/?LinkId=317598.

        public JsonResult UpdatetPurchaseCostAndSellPrice(pur_Purchase PurchaseCart)
        {
            var v = db.pur_Purchase.Where(I => I.BillNo == PurchaseCart.BillNo && I.PurchaseItemNameAr == PurchaseCart.PurchaseItemNameAr).FirstOrDefault();

            if (v != null)
            {
                v.ItemSalePrice    = PurchaseCart.ItemSalePrice;
                v.ItemCostPurchase = PurchaseCart.ItemCostPurchase;

                v.UpLoaded        = false;
                db.Entry(v).State = EntityState.Modified;
                db.SaveChanges();
            }
            var totalCost = db.pur_Purchase.Where(I => I.BillNo == PurchaseCart.BillNo).Sum(s => s.ItemCostPurchase);
            var xx        = db.pur_Bills.Where(b => b.BillNo == PurchaseCart.BillNo).ToList();
            var billID    = db.pur_Bills.Find(xx.FirstOrDefault().BillID).BillID;

            if (billID > 0)
            {
                var bill = db.pur_Bills.Find(billID);
                if (ModelState.IsValid)
                {
                    bill.TotalCostPurchase = totalCost;
                    bill.UpLoaded          = false;
                    db.Entry(bill).State   = EntityState.Modified;
                    db.SaveChanges();
                }
            }
            return(Json(1));
        }
Exemplo n.º 2
0
        void AddItemToStore(pur_Purchase pur, int InvertoryToID)
        {
            string constr = ConfigurationManager.ConnectionStrings["DBConnectionString"].ConnectionString;

            using (SqlConnection con = new SqlConnection(constr))
            {
                SqlCommand MyCommnd = new SqlCommand("[api_MoveItemsToStore]", con);
                MyCommnd.CommandType = CommandType.StoredProcedure;
                MyCommnd.Parameters.AddWithValue("@ItemID", pur.ItemID);
                MyCommnd.Parameters.AddWithValue("@ItemNameAr", pur.PurchaseItemNameAr);
                MyCommnd.Parameters.AddWithValue("@ItemQuantity", pur.PurchaseItemQuantity);
                MyCommnd.Parameters.AddWithValue("@ItemSalePrice", pur.ItemSalePrice);
                MyCommnd.Parameters.AddWithValue("@ItemPuchasePrice", pur.ItemPurchasePrice);
                MyCommnd.Parameters.AddWithValue("@ItemHistoryDecription", "توريد بضاعة جديدة");
                MyCommnd.Parameters.AddWithValue("@ItemHistoryProccessTypeID", 3);
                MyCommnd.Parameters.AddWithValue("@InventoryID", InvertoryToID);
                MyCommnd.Parameters.AddWithValue("@CategoryID", pur.CategoryID);
                MyCommnd.Parameters.AddWithValue("@ItemPurchaseCurrencyID", 1);
                MyCommnd.Parameters.AddWithValue("@PurchaseItemID", pur.PurchaseItemID);
                var            dt  = new DataTable();
                SqlDataAdapter adp = new SqlDataAdapter(MyCommnd);
                DataSet        ds  = new DataSet();
                // string temp = "";
                if (con.State == ConnectionState.Closed)
                {
                    con.Open();
                }
                adp.Fill(dt);
                //cmd.ExecuteNonQuery();
                con.Close();
            }
        }
Exemplo n.º 3
0
        public async Task <ActionResult> DeleteConfirmed(int id)
        {
            pur_Purchase pur_Purchase = await db.pur_Purchase.FindAsync(id);

            db.pur_Purchase.Remove(pur_Purchase);
            await db.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
Exemplo n.º 4
0
        public async Task <ActionResult> Edit([Bind(Include = "PurchaseItemID,PurchaseItemNameAr,PurchaseItemNameEn,PurchaseItemQuantity,PurchaseItemPriceSDG,PurchaseItemPriceUSD,SuplierID,CategoryID,SubCategoryID,PurchaseItemAddedDate,ItemID,BillNo,PurchaseStatusID")] pur_Purchase pur_Purchase)
        {
            if (ModelState.IsValid)
            {
                db.Entry(pur_Purchase).State = EntityState.Modified;
                await db.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            return(View(pur_Purchase));
        }
Exemplo n.º 5
0
        // POST: purshaseBill/Create
        // To protect from overposting attacks, please enable the specific properties you want to bind to, for
        // more details see http://go.microsoft.com/fwlink/?LinkId=317598.

        public JsonResult UpdatetPurchaseCostAndSellPrice(pur_Purchase PurchaseCart)
        {
            var v = db.pur_Purchase.Where(I => I.BillNo == PurchaseCart.BillNo && I.ItemID == PurchaseCart.ItemID).FirstOrDefault();

            if (v != null)
            {
                v.ItemSalePrice    = PurchaseCart.ItemSalePrice;
                v.ItemCostPurchase = PurchaseCart.ItemCostPurchase;

                v.UpLoaded = false;
                db.SaveChanges();
            }
            return(Json(1));
        }
Exemplo n.º 6
0
        // GET: Purchase/Delete/5
        public async Task <ActionResult> Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            pur_Purchase pur_Purchase = await db.pur_Purchase.FindAsync(id);

            if (pur_Purchase == null)
            {
                return(HttpNotFound());
            }
            return(View(pur_Purchase));
        }
Exemplo n.º 7
0
        public JsonResult ComplatePurchaseOrder
            (DateTime chequeNumberDate, string OrderNumber, decimal OrderpaymentAmount, string CategoryIDArray, string ItemIDArray, string NamesArray, string ItempurchasePriceArray, string QuantitiesArray, decimal OrderAmount, int SuplierID, string SuplierName, int paymentMethodeID, string chequeNumber, string chequeBransh)
        {
            var Remaining = OrderAmount - OrderpaymentAmount;

            int[]    ItemIDs     = Array.ConvertAll(ItemIDArray.Split(','), int.Parse);
            string[] Names       = NamesArray.Split(',');
            int[]    CategoryIDs = Array.ConvertAll(CategoryIDArray.Split(','), int.Parse);

            int[] ItemspurchasePrice = Array.ConvertAll(ItempurchasePriceArray.Split(','), int.Parse);
            int[] Quantities         = Array.ConvertAll(QuantitiesArray.Split(','), int.Parse);

            string decription = " إضافة بضاعة بقيمة : ";

            decription += " " + OrderAmount + " ";
            decription += "من المورد : ";
            decription += SuplierName + "";
            // ################################################ //
            //        Phase 0: select purchaseNo         //
            try
            {
                #region
                var    NewbillSNo             = db.pur_Bills.Count();
                var    NewbillNo              = "";
                string DateFormateToInventory = "PUR" + DateTime.Now.ToString("yyyyMMdd");
                if (NewbillSNo > 0)
                {
                    NewbillNo = db.pur_Bills.OrderByDescending(o => o.BillID).FirstOrDefault().BillNo;
                    var LastNo = NewbillNo.Remove(0, DateFormateToInventory.Length);
                    NewbillNo = DateFormateToInventory + (int.Parse(LastNo) + 1).ToString(); //NewbillNo.Substring(0, DateFormateToInventory.) +Int32.Parse(NewbillNo.Substring(9, -1)+1);
                }
                else
                {
                    NewbillNo = DateFormateToInventory + "1";
                }
                Console.Write("dsdsa");
                #endregion

                // ################################################ //
                //             Phase 2: Insert in   pur_BillDetails         //
                // ################################################ //
                #region
                var billDetailes = new pur_BillDetails
                {
                    Amount                 = OrderAmount,
                    BillDetailsDate        = DateTime.Now,
                    BillDetailsDescription = decription,
                    BillNo                 = NewbillNo,
                    PaymentMethodID        = paymentMethodeID,
                    ChequeNo               = chequeNumber,
                    ChequeBank             = chequeBransh,
                    UpLoaded               = false,
                    ChequeDate             = chequeNumberDate,
                    ChequeBankBranch       = chequeBransh,
                };
                db.pur_BillDetails.Add(billDetailes);
                db.SaveChanges();
                #endregion
                // ################################################ //
                //        Phase 2: Insert Purshase Bill (order)     //
                // ################################################ //

                string constr = ConfigurationManager.ConnectionStrings["DBConnectionString"].ConnectionString;

                // ################################################ //
                //             Phase 2: Insert Purshase History     //
                // ################################################ //

                // ################################################ //
                //             Phase 3: Empty Parshase Cart
                // ################################################ //
                #region
                using (SqlConnection con2 = new SqlConnection(constr))
                {
                    using (SqlCommand cmd2 = new SqlCommand("Delete_PurchaseCart"))
                    {
                        cmd2.Connection = con2;
                        con2.Open();
                        cmd2.ExecuteNonQuery();
                        con2.Close();
                    }
                }
                #endregion

                // ################################################ //
                //        Phase 2: Insert Purshase      //
                // ################################################ //
                #region
                for (int i = 0; i < Names.Length; i++)
                {
                    var name     = Names[i];
                    var quantity = Quantities[i];
                    //   var sellamount = ItemsSellPrice[i];
                    var itemID = ItemIDs[i];
                    // var ItemInventoryID = ItemInventoryIDs[i];

                    //var ItemCostPurchase = ItemsCostPurchase[i];
                    var ItempurchasePrice = ItemspurchasePrice[i];

                    var purchase = new pur_Purchase
                    {
                        BillNo                  = NewbillNo,
                        CategoryID              = CategoryIDs[i],
                        ItemCostPurchase        = 0,
                        ItemID                  = itemID,
                        ItemPurchaseCurrencyID  = 1,
                        ItemPurchasePrice       = ItempurchasePrice,
                        ItemSalePrice           = 0,
                        ItemSaleCurrencyID      = 1,
                        PurchaseItemID          = itemID,
                        ItemTotalPurchaseAmount = ItempurchasePrice * quantity,
                        PurchaseItemNameAr      = name,
                        PurchaseItemNameEn      = name,
                        PurchaseItemAddedDate   = DateTime.Now,
                        PurchaseItemQuantity    = quantity,
                        PurchaseStatusID        = 0,
                        IsReturn                = false,
                        SubCategoryID           = 1,
                        UpLoaded                = false,
                        BarCode                 = "",
                        SuplierID               = SuplierID,
                        SuplierName             = SuplierName
                    };
                    db.pur_Purchase.Add(purchase);
                    db.SaveChanges();
                }
                #endregion

                // ################################################ //
                //     (OPtional)  Phase 5: Insert Purshases as Requseted  Items    //
                // ################################################ //

                // ############################################## //
                //   Phase 6: Insert Suplier payment transaction  //
                // ############################################## //
                #region
                var     suplier = db.pay_SuplierAcounts.Where(s => s.SuplierID == SuplierID).Count();
                decimal?LastSuplierAcountAmount = 0;
                if (suplier > 0)
                {
                    LastSuplierAcountAmount = db.pay_SuplierAcounts.OrderBy(c => 1 == 1).Skip(suplier - 1).FirstOrDefault().SuplierAcountAmount;
                }
                else
                {
                    LastSuplierAcountAmount = 0;
                }
                var suplierPayment = new pay_SuplierAcounts();
                //suplierPayment.SuplierID = SuplierID;
                //suplierPayment.SuplierName = SuplierName;
                //suplierPayment.SuplierAcountCredit = OrderAmount;
                //suplierPayment.CustomeAcountDepit = 0;
                //suplierPayment.UpLoaded = false;
                //suplierPayment.PaymentDescription = decription;
                //suplierPayment.PaymentMethodID = paymentMethodeID;
                //suplierPayment.SuplierAcountTransactionDate = DateTime.Now;
                //suplierPayment.SuplierAcountAmount = LastSuplierAcountAmount + OrderAmount;
                //db.pay_SuplierAcounts.Add(suplierPayment);
                //db.SaveChanges();
                decription  = " دفع مبلغ بقيمة : ";
                decription += " " + OrderpaymentAmount + " ";
                decription += " والمتبقى : ";
                decription += Remaining + "  ";
                decription += "الى المورد : ";
                decription += SuplierName + "";
                suplierPayment.SuplierID                    = SuplierID;
                suplierPayment.SuplierName                  = SuplierName;
                suplierPayment.SuplierAcountCredit          = 0;
                suplierPayment.SuplierAcountDepit           = OrderpaymentAmount;
                suplierPayment.UpLoaded                     = false;
                suplierPayment.PaymentDescription           = decription;
                suplierPayment.PaymentMethodID              = paymentMethodeID;
                suplierPayment.SuplierAcountAmount          = 0;///(LastSuplierAcountAmount + OrderAmount) - OrderpaymentAmount;
                suplierPayment.SuplierAcountTransactionDate = DateTime.Now;
                db.pay_SuplierAcounts.Add(suplierPayment);
                db.SaveChanges();


                #endregion
                // ############################################## //
                //   Phase 6: Insert bill payment transaction  //
                // ############################################## //
                #region
                string Billdecription = " إضافة بضاعة بقيمة : ";
                Billdecription += " " + OrderAmount + " ";
                Billdecription += "من المورد : ";
                Billdecription += SuplierName + "";
                var     lastPayMent       = db.pur_Bills.Count();
                decimal?lastPayMentAmount = 0;
                if (lastPayMent > 0)
                {
                    lastPayMentAmount = db.pur_Bills.OrderBy(c => 1 == 1).Skip(lastPayMent - 1).FirstOrDefault().BillNetAmount;
                }
                else
                {
                    lastPayMentAmount = 0;
                }
                var bill = new pur_Bills
                {
                    TotalCostPurchase   = 0,
                    BillNo              = NewbillNo,
                    SuplierID           = SuplierID,
                    SuplierName         = SuplierName,
                    TotalAmount         = OrderAmount,
                    BillPaidAmount      = OrderpaymentAmount,
                    BillRemainingAmount = Remaining,
                    BillStatusID        = 0,
                    BillDescription     = decription,
                    BillPaymentStatus   = 1,
                    BillDate            = DateTime.Now,
                    BillTotalAmount     = OrderAmount,
                    BillIsReturned      = false,
                    BillNetAmount       = OrderAmount,
                    UpLoaded            = false,
                    PaymentMethodID     = paymentMethodeID,
                };
                db.pur_Bills.Add(bill);
                db.SaveChanges();
                #endregion
                if (Remaining == 0)
                {
                    Functions.Functions.InsertPaymentHistory(0, OrderpaymentAmount, decription, paymentMethodeID);
                }
                else
                {
                    Functions.Functions.InsertPaymentHistory(0, OrderpaymentAmount, decription, paymentMethodeID);
                    Functions.Functions.InsertPaymentHistory(Remaining, 0, decription, paymentMethodeID);
                }
            }
            catch (Exception ex)
            {
                return(Json(2));
            }

            return(Json(1));
        }