public void UpdatePayment(PaymentReceiptModel payment) { object op = null; InventoryClass obj = new InventoryClass(); if (payment.PanReceiptNo == true) { int x = 0; dbobj1.Insert_or_Update("delete from AccountsLedgerTable where Particulars = 'Receipt (" + payment.ReceiptNo + ")'", ref x); dbobj1.Insert_or_Update("delete from AccountsLedgerTable where Particulars = 'Receipt_" + payment.Discount1 + " (" + payment.ReceiptNo + ")'", ref x); dbobj1.Insert_or_Update("delete from AccountsLedgerTable where Particulars = 'Receipt_" + payment.Discount2 + " (" + payment.ReceiptNo + ")'", ref x); dbobj1.Insert_or_Update("delete from CustomerLedgerTable where Particular = 'Payment Received(" + payment.ReceiptNo + ")'", ref x); dbobj1.Insert_or_Update("delete from Payment_Receipt where Receipt_No='" + payment.ReceiptNo + "'", ref x); int Curr_Credit = 0; int Credit_Limit = 0; dbobj.ExecuteScalar("Select Cr_Limit from customer where Cust_ID = '" + payment.CustomerID + "'", ref Credit_Limit); dbobj.ExecuteScalar("Select Curr_Credit from customer where Cust_ID = '" + payment.CustomerID + "'", ref Curr_Credit); if (Curr_Credit <= Credit_Limit) { Curr_Credit = Curr_Credit + int.Parse(payment.ReceivedAmount); Curr_Credit = Curr_Credit - int.Parse(payment.TotalRec); if (@Curr_Credit >= @Credit_Limit) { dbobj1.Insert_or_Update("update customer set Curr_Credit = '" + Credit_Limit + "' where Cust_ID = '" + payment.CustomerID + "'", ref x); } else { dbobj1.Insert_or_Update("update customer set Curr_Credit = '" + Curr_Credit + "' where Cust_ID = '" + payment.CustomerID + "'", ref x); } } else { Curr_Credit = Curr_Credit + int.Parse(payment.ReceivedAmount); Curr_Credit = Curr_Credit - int.Parse(payment.TotalRec); dbobj1.Insert_or_Update("update customer set Cr_Limit = '" + Curr_Credit + "' where Cust_ID = '" + payment.CustomerID + "'", ref x); } obj.InsertPaymentReceived(payment); dbobj.ExecProc(DbOperations_LATEST.OprType.Insert, "ProCustLedgerEntry", ref op, "@Cust_Name", payment.CustomerName, "@City", payment.City, "@Amount", payment.Amount, "@Rec_Acc_Type", payment.AccountType, "@Receipt", payment.Receipt, "@Receipt_No", payment.ReceiptNo, "@ActualAmount", payment.ReceivedAmount, "@RecDate", payment.RecDate); if (payment.Discount1 != "" && payment.Discount1 != "0") { dbobj.ExecProc(DbOperations_LATEST.OprType.Insert, "ProSpacialDiscountEntry", ref op, "@Cust_ID", payment.Cust_ID, "@Receipt", "Save", "@Receipt_No", payment.ReceiptNo, "@Amount", payment.Discount1, "@Ledger_ID", payment.DiscLedgerID1, "@RecDate", payment.RecDate, "@DisType", payment.Discount1); } if (payment.Discount2 != "" && payment.Discount2 != "0") { dbobj.ExecProc(DbOperations_LATEST.OprType.Insert, "ProSpacialDiscountEntry", ref op, "@Cust_ID", payment.Cust_ID, "@Receipt", "Save", "@Receipt_No", payment.ReceiptNo, "@Amount", payment.Discount1, "@Ledger_ID", payment.DiscLedgerID2, "@RecDate", payment.RecDate, "@DisType", payment.Discount2); } } else { obj.InsertPaymentReceived(payment); dbobj.ExecProc(DbOperations_LATEST.OprType.Insert, "ProCustLedgerEntry", ref op, "@Cust_Name", payment.CustomerName, "@City", payment.City, "@Amount", payment.Amount, "@Rec_Acc_Type", payment.AccountType, "@Receipt", payment.Receipt, "@Receipt_No", payment.ReceiptNo, "@ActualAmount", payment.ReceivedAmount, "@RecDate", payment.RecDate); if (payment.Discount1 != "" && payment.Discount1 != "0") { dbobj.ExecProc(DbOperations_LATEST.OprType.Insert, "ProSpacialDiscountEntry", ref op, "@Cust_ID", payment.Cust_ID, "@Receipt", "Save", "@Receipt_No", payment.ReceiptNo, "@Amount", payment.Discount1, "@Ledger_ID", payment.DiscLedgerID1, "@RecDate", payment.RecDate, "@DisType", payment.DiscountType1); } if (payment.Discount2 != "" && payment.Discount2 != "0") { dbobj.ExecProc(DbOperations_LATEST.OprType.Insert, "ProSpacialDiscountEntry", ref op, "@Cust_ID", payment.Cust_ID, "@Receipt", "Save", "@Receipt_No", payment.ReceiptNo, "@Amount", payment.Discount1, "@Ledger_ID", payment.DiscLedgerID2, "@RecDate", payment.RecDate, "@DisType", payment.DiscountType2); } int x = 0; int Curr_Credit = 0; int Credit_Limit = 0; dbobj.ExecuteScalar("Select Cr_Limit from customer where Cust_ID = '" + payment.OldCust_ID + "'", ref Credit_Limit); dbobj.ExecuteScalar("Select Curr_Credit from customer where Cust_ID = '" + payment.OldCust_ID + "'", ref Curr_Credit); if (Curr_Credit < Credit_Limit) { Curr_Credit = Curr_Credit + int.Parse(payment.ReceivedAmount); if (@Curr_Credit >= @Credit_Limit) { dbobj1.Insert_or_Update("update customer set Curr_Credit = '" + Credit_Limit + "' where Cust_ID = '" + payment.CustomerID + "'", ref x); } else { dbobj1.Insert_or_Update("update customer set Curr_Credit = '" + Curr_Credit + "' where Cust_ID = '" + payment.CustomerID + "'", ref x); } } else { Curr_Credit = Curr_Credit + int.Parse(payment.ReceivedAmount); //Add by vikas 12.09.09 Curr_Credit = Curr_Credit - int.Parse(payment.TotalRec); //Add by vikas 12.09.09 dbobj1.Insert_or_Update("update customer set Cr_Limit = '" + Curr_Credit + "' where Cust_ID = '" + payment.CustomerID + "'", ref x); } } }