/** * Create Line Reversal * @return new reversed CashLine */ public MCashLine CreateReversal() { MCash parent = GetParent(); if (parent.IsProcessed()) { // saved parent = MCash.Get(GetCtx(), parent.GetAD_Org_ID(), parent.GetStatementDate(), parent.GetC_Currency_ID(), Get_TrxName()); } // MCashLine reversal = new MCashLine(parent); reversal.SetClientOrg(this); reversal.SetC_BankAccount_ID(GetC_BankAccount_ID()); reversal.SetC_Charge_ID(GetC_Charge_ID()); reversal.SetC_Currency_ID(GetC_Currency_ID()); reversal.SetC_Invoice_ID(GetC_Invoice_ID()); reversal.SetCashType(GetCashType()); reversal.SetDescription(GetDescription()); reversal.SetIsGenerated(true); // reversal.SetAmount(Decimal.Negate(GetAmount())); //if (GetDiscountAmt() == null) //// SetDiscountAmt(Env.ZERO); //else reversal.SetDiscountAmt(Decimal.Negate(GetDiscountAmt())); //if (GetWriteOffAmt() == null) // SetWriteOffAmt(Env.ZERO); //else reversal.SetWriteOffAmt(Decimal.Negate(GetWriteOffAmt())); reversal.AddDescription("(" + GetLine() + ")"); return(reversal); }
/** * Parent Cosntructor * @param cash parent */ public MCashLine(MCash cash) : this(cash.GetCtx(), 0, cash.Get_TrxName()) { SetClientOrg(cash); SetC_Cash_ID(cash.GetC_Cash_ID()); _parent = cash; _cashBook = _parent.GetCashBook(); }
/** * Get Cash (parent) * @return cash */ public MCash GetParent() { if (_parent == null) { _parent = new MCash(GetCtx(), GetC_Cash_ID(), Get_TrxName()); } return(_parent); }
//Get Cash Journal Detail Added by Bharat 16/12/2016 public Dictionary <string, string> GetCashJournal(Ctx ctx, string fields) { string[] paramValue = fields.Split(','); //Assign parameter value int C_CashJournal_ID = Util.GetValueOfInt(paramValue[0].ToString()); //End Assign parameter value MCash cash = new MCash(ctx, C_CashJournal_ID, null); Dictionary <string, string> result = new Dictionary <string, string>(); result["C_Currency_ID"] = cash.GetC_Currency_ID().ToString(); result["DateAcct"] = cash.GetDateAcct().ToString(); return(result); }
/// <summary> /// Load Cash Line /// </summary> /// <param name="cash">journal</param> /// <param name="cb">cash book</param> /// <returns>DocLine Array</returns> private DocLine[] LoadLines(MCash cash, MCashBook cb) { List <DocLine> list = new List <DocLine>(); MCashLine[] lines = cash.GetLines(false); for (int i = 0; i < lines.Length; i++) { MCashLine line = lines[i]; DocLine_Cash docLine = new DocLine_Cash(line, this); // list.Add(docLine); } // Return Array DocLine[] dls = new DocLine[list.Count]; dls = list.ToArray(); return(dls); }
/// <summary> /// Load Specific Document Details /// </summary> /// <returns>error message or null</returns> public override String LoadDocumentDetails() { MCash cash = (MCash)GetPO(); SetDateDoc(cash.GetStatementDate()); BeginningBalance = cash.GetBeginningBalance(); HeaderCasbookID = cash.GetC_CashBook_ID(); // Amounts SetAmount(Doc.AMTTYPE_Gross, cash.GetStatementDifference()); // Set CashBook Org & Currency MCashBook cb = MCashBook.Get(GetCtx(), cash.GetC_CashBook_ID()); SetC_CashBook_ID(cb.GetC_CashBook_ID()); SetC_Currency_ID(cb.GetC_Currency_ID()); // Contained Objects _lines = LoadLines(cash, cb); log.Fine("Lines=" + _lines.Length); return(null); }
private bool UpdateCbAndLine() { // Update Cash Journal if (!UpdateHeader()) { log.Warning("Cannot update cash journal."); return(false); } // Update Cashbook and CashbookLine MCash parent = GetParent(); MCashBook cashbook = new MCashBook(GetCtx(), parent.GetC_CashBook_ID(), Get_TrxName()); if (cashbook.GetCompletedBalance() == 0) { cashbook.SetCompletedBalance(parent.GetBeginningBalance()); } cashbook.SetRunningBalance(Decimal.Add(Decimal.Subtract(cashbook.GetRunningBalance(), old_ebAmt), new_ebAmt)); //if (cashbook.GetRunningBalance() == 0) //{ // cashbook.SetRunningBalance // (Decimal.Add(Decimal.Add(Decimal.Subtract(cashbook.GetRunningBalance(), old_ebAmt), new_ebAmt),cashbook.GetCompletedBalance())); //} //else //{ // cashbook.SetRunningBalance(Decimal.Add(Decimal.Subtract(cashbook.GetRunningBalance(), old_ebAmt), new_ebAmt)); //} if (!cashbook.Save()) { log.Warning("Cannot update running balance."); return(false); } DataTable dtCashbookLine; int C_CASHBOOKLINE_ID = 0; string sql = "SELECT C_CASHBOOKLINE_ID FROM C_CASHBOOKLINE WHERE C_CASHBOOK_ID=" + cashbook.GetC_CashBook_ID() + " AND DATEACCT=" + DB.TO_DATE(parent.GetDateAcct()) + " AND AD_ORG_ID=" + GetAD_Org_ID(); dtCashbookLine = DB.ExecuteDataset(sql, null, null).Tables[0]; if (dtCashbookLine.Rows.Count > 0) { C_CASHBOOKLINE_ID = Util.GetValueOfInt(dtCashbookLine.Rows[0] .ItemArray[0]); } MCashbookLine cashbookLine = new MCashbookLine(GetCtx(), C_CASHBOOKLINE_ID, Get_TrxName()); if (C_CASHBOOKLINE_ID == 0) { cashbookLine.SetC_CashBook_ID(cashbook.GetC_CashBook_ID()); cashbookLine.SetAD_Org_ID(GetAD_Org_ID()); cashbookLine.SetAD_Client_ID(GetAD_Client_ID()); cashbookLine.SetEndingBalance (Decimal.Add(Decimal.Add(Decimal.Subtract(cashbookLine.GetEndingBalance(), old_ebAmt), new_ebAmt), cashbook.GetCompletedBalance())); } else { cashbookLine.SetEndingBalance(Decimal.Add(Decimal.Subtract(cashbookLine.GetEndingBalance(), old_ebAmt), new_ebAmt)); } cashbookLine.SetDateAcct(parent.GetDateAcct()); cashbookLine.SetStatementDifference(Decimal.Add(Decimal.Subtract(cashbookLine.GetStatementDifference(), old_sdAmt), new_sdAmt)); if (!cashbookLine.Save()) { log.Warning("Cannot create/update cashbook line."); return(false); } return(true); }
protected override string DoIt() { MCash cashheader = new MCash(GetCtx(), GetRecord_ID(), Get_Trx()); sql = "select C_Currency_ID from C_CashBook where c_Cashbook_id=" + cashheader.GetC_CashBook_ID(); int C_Currencyheader_ID = Util.GetValueOfInt(DB.ExecuteScalar(sql, null, Get_Trx())); sql = "select * from C_Cashline WHERE C_Cash_ID=" + GetRecord_ID(); DataSet dscashline = DB.ExecuteDataset(sql, null, Get_Trx()); if (dscashline != null) { if (dscashline.Tables[0].Rows.Count > 0) { for (i = 0; i < dscashline.Tables[0].Rows.Count; i++) { cashline = new MCashLine(GetCtx(), Util.GetValueOfInt(dscashline.Tables[0].Rows[i]["C_CashLine_ID"]), Get_Trx()); if (cashline.GetCashType().ToString() == "A" || cashline.GetCashType().ToString() == "F") { sql = "Select * from C_Cash where C_CashBook_Id=" + cashline.GetC_CashBook_ID() + " and docstatus='DR' and DateAcct=" + GlobalVariable.TO_DATE(DateTime.Now, true); DataSet dscashbook = DB.ExecuteDataset(sql, null, Get_Trx()); if (dscashbook != null) { if (dscashbook.Tables[0].Rows.Count > 0) { int j; for (j = 0; j < dscashbook.Tables[0].Rows.Count; j++) { cash = new MCash(GetCtx(), Util.GetValueOfInt(dscashbook.Tables[0].Rows[j]["C_Cash_ID"]), Get_Trx()); if (!_cashIds.Contains(cash.GetC_Cash_ID())) { _cashIds.Add(cash.GetC_Cash_ID()); } //ViennaAdvantage.Model.MCashLine cashline1 = new ViennaAdvantage.Model.MCashLine(GetCtx(), 0, Get_Trx()); MCashLine cashline1 = new MCashLine(GetCtx(), 0, Get_Trx()); cashline1.SetC_Cash_ID(cash.GetC_Cash_ID()); cashline1.SetAD_Client_ID(cash.GetAD_Client_ID()); cashline1.SetAD_Org_ID(cash.GetAD_Org_ID()); if (cashline.GetCashType().ToString() == "A") { cashline1.SetCashType("F"); } if (cashline.GetCashType().ToString() == "F") { cashline1.SetCashType("A"); } // Added by Bharat as discussed with Ravikant on 22 March 2017 if (cashline1.Get_ColumnIndex("C_ConversionType_ID") > 0) { cashline1.SetC_ConversionType_ID(cashline.GetC_ConversionType_ID()); } cashline1.SetC_CashBook_ID(cashheader.GetC_CashBook_ID()); cashline1.SetC_BPartner_ID(cashline.GetC_BPartner_ID()); sql = "select C_Currency_ID from C_CashBook where c_Cashbook_id=" + cash.GetC_CashBook_ID(); Currency_ID = Util.GetValueOfInt(DB.ExecuteScalar(sql, null, Get_Trx())); if (Currency_ID == C_Currencyheader_ID) { cashline1.SetC_Currency_ID(C_Currencyheader_ID); cashline1.SetAmount(Decimal.Negate(cashline.GetAmount())); cashline1.SetConvertedAmt(Util.GetValueOfString(Decimal.Negate(cashline.GetAmount()))); } else { //cashline1.SetC_Currency_ID(Currency_ID); // Change by Bharat as discussed with Ravikant on 22 March 2017 cashline1.SetC_Currency_ID(C_Currencyheader_ID); if (cashline1.Get_ColumnIndex("C_ConversionType_ID") > 0) { //_Curencyrate = MConversionRate.GetRate(C_Currencyheader_ID, Currency_ID, cash.GetDateAcct(), cashline.GetC_ConversionType_ID(), // cash.GetAD_Client_ID(), cash.GetAD_Org_ID()); convertedamount = Decimal.Negate(Util.GetValueOfDecimal(cashline.GetConvertedAmt())); // if converted amount not found then get amount based on currency conversion avaliable if (cashline.GetAmount() != 0 && convertedamount == 0) { convertedamount = MConversionRate.Convert(GetCtx(), Decimal.Negate(cashline.GetAmount()), Currency_ID, C_Currencyheader_ID, cash.GetDateAcct(), cashline.GetC_ConversionType_ID(), cash.GetAD_Client_ID(), cash.GetAD_Org_ID()); cashline.SetConvertedAmt(Util.GetValueOfString(Decimal.Negate(convertedamount))); } if (cashline.GetAmount() != 0 && convertedamount == 0) { return(Msg.GetMsg(GetCtx(), "NoCurrencyRateDefined")); } else if (cashline.GetAmount() == 0) { return("Amount Should be greater than zero"); } cashline1.SetAmount(convertedamount); cashline1.SetConvertedAmt(Util.GetValueOfString(Decimal.Negate(cashline.GetAmount()))); } else { sql = "select multiplyrate from c_conversion_rate where isactive='Y' and c_currency_id=" + C_Currencyheader_ID + " and c_currency_to_id=" + Currency_ID; _Curencyrate = Util.GetValueOfDecimal(DB.ExecuteScalar(sql, null, Get_Trx())); if (_Curencyrate == 0) { return(Msg.GetMsg(GetCtx(), "NoCurrencyRateDefined")); } else { convertedamount = Decimal.Round(Decimal.Multiply(_Curencyrate, Decimal.Negate(cashline.GetAmount())), 2); } cashline1.SetConvertedAmt(Util.GetValueOfString(convertedamount)); cashline1.SetAmount(convertedamount); } } cashline1.SetC_Charge_ID(cashline.GetC_Charge_ID()); if (cashline.GetCashType().ToString() == "A") { cashline1.SetVSS_PAYMENTTYPE("R"); } if (cashline.GetCashType().ToString() == "F") { cashline1.SetVSS_PAYMENTTYPE("P"); } cashline1.SetC_CashLine_ID_1(cashline.GetC_CashLine_ID()); if (!cashline1.Save()) { Rollback(); log.Severe("NotSaved"); return(" NotSaved Cashline1 [ Header Found ] "); } if (cashline.GetCashType().ToString() == "F") { cashline.SetC_CashLine_ID_1(cashline1.GetC_CashLine_ID()); } if (!cashline.Save()) { Rollback(); log.Severe("Not Saved"); return(" NotSaved Cashline [ Header Found ] "); } //change by Amit 1-june-2016 after discussion with ravikant //int BeginBal = Util.GetValueOfInt(DB.ExecuteScalar("select completedbalance from c_cashbook where c_cashbook_id=" + cash.GetC_CashBook_ID(), null, Get_Trx())); //cash.SetBeginningBalance(BeginBal); //if (!cash.Save(Get_Trx())) //{ // Rollback(); // log.Severe("Not Saved"); // return " NotSaved Cash [ Header Found ] "; //} //end break; } } else { dscashbook.Dispose(); MCash cash1 = new MCash(GetCtx(), 0, Get_Trx()); cash1.SetAD_Client_ID(cashheader.GetAD_Client_ID()); cash1.SetAD_Org_ID(cashheader.GetAD_Org_ID()); cash1.SetC_DocType_ID(cashheader.GetC_DocType_ID()); cash1.SetName(Util.GetValueOfString(System.DateTime.Today.ToShortDateString())); cash1.SetC_CashBook_ID(cashline.GetC_CashBook_ID()); cash1.SetDateAcct(DateTime.Now); cash1.SetStatementDate(DateTime.Now); //change by Amit 1-june-2016 after discussion with ravikant int BeginBal = Util.GetValueOfInt(DB.ExecuteScalar("select SUM(completedbalance + runningbalance) from c_cashbook where c_cashbook_id=" + cashline.GetC_CashBook_ID(), null, Get_Trx())); cash1.SetBeginningBalance(BeginBal); //end //Change by Bharat as discussed with Ravikant on 22 March 2017 sql = "select C_Currency_ID from C_CashBook where c_Cashbook_id=" + cash1.GetC_CashBook_ID(); Currency_ID = Util.GetValueOfInt(DB.ExecuteScalar(sql, null, Get_Trx())); if (cash1.Get_ColumnIndex("C_Currency_ID") > 0) { cash1.SetC_Currency_ID(Currency_ID); } //End if (!cash1.Save()) { Rollback(); VAdvantage.Model.ValueNamePair ppE = VLogger.RetrieveError(); if (ppE != null) { return(ppE.GetName() + "<--->" + ppE.GetValue()); } return("cash1 not saved [header not found->]"); } // return cash1.GetC_Cash_ID() + "suc"; if (!_cashIds.Contains(cash1.GetC_Cash_ID())) { _cashIds.Add(cash1.GetC_Cash_ID()); } MCashLine cashline1 = new MCashLine(GetCtx(), 0, Get_Trx()); cashline1.SetC_Cash_ID(cash1.GetC_Cash_ID()); cashline1.SetAD_Client_ID(cash1.GetAD_Client_ID()); cashline1.SetAD_Org_ID(cash1.GetAD_Org_ID()); if (cashline.GetCashType().ToString() == "A") { cashline1.SetCashType("F"); } if (cashline.GetCashType().ToString() == "F") { cashline1.SetCashType("A"); } if (cashline1.Get_ColumnIndex("C_ConversionType_ID") > 0) { cashline1.SetC_ConversionType_ID(cashline.GetC_ConversionType_ID()); } cashline1.SetC_CashBook_ID(cashheader.GetC_CashBook_ID()); cashline1.SetC_BPartner_ID(cashline.GetC_BPartner_ID()); //Change by Bharat as discussed with Ravikant on 22 March 2017 //sql = "select C_Currency_ID from C_CashBook where c_Cashbook_id=" + cash1.GetC_CashBook_ID(); //Currency_ID = Util.GetValueOfInt(DB.ExecuteScalar(sql, null, Get_Trx())); if (Currency_ID == C_Currencyheader_ID) { cashline1.SetAmount(Decimal.Negate(cashline.GetAmount())); cashline1.SetC_Currency_ID(C_Currencyheader_ID); cashline1.SetConvertedAmt(Util.GetValueOfString(Decimal.Negate(cashline.GetAmount()))); } else { //Change by Bharat as discussed with Ravikant on 22 March 2017 cashline1.SetC_Currency_ID(C_Currencyheader_ID); if (cashline1.Get_ColumnIndex("C_ConversionType_ID") > 0) { //_Curencyrate = MConversionRate.GetRate(C_Currencyheader_ID, Currency_ID, cashheader.GetDateAcct(), cashline.GetC_ConversionType_ID(), // cashheader.GetAD_Client_ID(), cashheader.GetAD_Org_ID()); convertedamount = Decimal.Negate(Util.GetValueOfDecimal(cashline.GetConvertedAmt())); // if converted amount not found then get amount based on currency conversion avaliable if (cashline.GetAmount() != 0 && convertedamount == 0) { convertedamount = MConversionRate.Convert(GetCtx(), Decimal.Negate(cashline.GetAmount()), Currency_ID, C_Currencyheader_ID, cash1.GetDateAcct(), cashline.GetC_ConversionType_ID(), cash1.GetAD_Client_ID(), cash1.GetAD_Org_ID()); cashline.SetConvertedAmt(Util.GetValueOfString(Decimal.Negate(convertedamount))); } if (cashline.GetAmount() != 0 && convertedamount == 0) { return(Msg.GetMsg(GetCtx(), "NoCurrencyRateDefined")); } else if (cashline.GetAmount() == 0) { return("Amount Should be greater than zero"); } cashline1.SetAmount(convertedamount); cashline1.SetConvertedAmt(Util.GetValueOfString(Decimal.Negate(cashline.GetAmount()))); } else { sql = "select multiplyrate from c_conversion_rate where isactive='Y' and c_currency_id=" + C_Currencyheader_ID + " and c_currency_to_id=" + Currency_ID; _Curencyrate = Util.GetValueOfDecimal(DB.ExecuteScalar(sql, null, Get_Trx())); if (_Curencyrate == 0) { return(Msg.GetMsg(GetCtx(), "NoCurrencyRateDefined")); } else { convertedamount = Decimal.Round(Decimal.Multiply(_Curencyrate, Decimal.Negate(cashline.GetAmount())), 2); } cashline1.SetConvertedAmt(Util.GetValueOfString(convertedamount)); cashline1.SetAmount(convertedamount); } } cashline1.SetC_Charge_ID(cashline.GetC_Charge_ID()); if (cashline.GetCashType().ToString() == "A") { cashline1.SetVSS_PAYMENTTYPE("R"); } if (cashline.GetCashType().ToString() == "F") { cashline1.SetVSS_PAYMENTTYPE("P"); } cashline1.SetC_CashLine_ID_1(cashline.GetC_CashLine_ID()); if (!cashline1.Save(Get_Trx())) { Rollback(); log.Severe("NotSaved"); return(" NotSaved Cashline1 [ Header not Found ] "); } if (cashline.GetCashType().ToString() == "F") { cashline.SetC_CashLine_ID_1(cashline1.GetC_CashLine_ID()); } if (!cashline.Save(Get_Trx())) { Rollback(); log.Severe("NotSaved"); return(" NotSaved Cashline [ Header not Found ] "); } //change by Amit 1-june-2016 after discussion with ravikant //int BeginBal = Util.GetValueOfInt(DB.ExecuteScalar("select completedbalance from c_cashbook where c_cashbook_id=" + cash1.GetC_CashBook_ID(), null, Get_Trx())); //cash1.SetBeginningBalance(BeginBal); //if (!cash1.Save()) //{ // Rollback(); // log.Severe("NotSaved"); // return " NotSaved Cash1 [ Header not Found(bb) ] "; //} //end } } else { //dscashbook.Dispose(); } } else { cashtype++; } } // Discussed with Ravikant it is re updating the Header so commented on 23-March-2017 by Bharat //decimal OpenBal = Util.GetValueOfDecimal(DB.ExecuteScalar("SELECT completedbalance FROM C_CashBook WHERE c_cashbook_id=" + cashheader.GetC_CashBook_ID() + "", null, Get_Trx())); //cashheader.SetBeginningBalance(OpenBal); //if (!cashheader.Save()) //{ // Rollback(); // log.Severe("Not Saved"); //} } else { dscashline.Dispose(); cashheader.SetGenerateCashBookTransfer("Y"); if (!cashheader.Save()) { Rollback(); log.Severe("NotSaved"); } return(Msg.GetMsg(GetCtx(), "NoCashLineExist")); } if (_cashIds.Count > 0) { for (int k = 0; k < _cashIds.Count; k++) { cash = new MCash(GetCtx(), _cashIds[k], Get_Trx()); cash.SetDocStatus(cash.CompleteIt()); if (!cash.Save()) { Rollback(); log.Severe("NotSaved"); } } } } cashheader.SetGenerateCashBookTransfer("Y"); if (!cashheader.Save()) { log.Severe("NotSaved"); } if (cashtype == i) { return(Msg.GetMsg(GetCtx(), "NoCashLineExist")); } return("Completed"); }
private TabDetails Save(PaymentInputValues inputs) { try { StringBuilder errorMsg = new StringBuilder(); string SucessMsg = ""; String newPaymentRule = inputs.cmbPayment; inputs._DateAcct = Convert.ToDateTime(inputs._DateAcct); DateTime?newDateAcct = Convert.ToDateTime(inputs._DateAcct); int newC_PaymentTerm_ID = inputs._C_PaymentTerm_ID; int newC_CashLine_ID = inputs._C_CashLine_ID; int newC_CashBook_ID = inputs._C_CashBook_ID; String newCCType = inputs.CCType; int newC_BankAccount_ID = 0; // B (Cash) (Currency) if (newPaymentRule.Equals(X_C_Order.PAYMENTRULE_Cash)) { newC_CashBook_ID = inputs.cmbBCashBook; //newDateAcct = (DateTime)bDateField.GetValue(); newDateAcct = Convert.ToDateTime(inputs.bDateField); } // K (CreditCard) Type, Number, Exp, Approval else if (newPaymentRule.Equals(X_C_Order.PAYMENTRULE_CreditCard)) { newCCType = inputs.cmbKType; } // T (Transfer) BPartner_Bank else if (newPaymentRule.Equals(MOrder.PAYMENTRULE_DirectDeposit) || newPaymentRule.Equals(MOrder.PAYMENTRULE_DirectDebit)) { // KeyNamePair myObj = (KeyNamePair)cmbTAccount.SelectedItem; } // P (PaymentTerm) PaymentTerm else if (newPaymentRule.Equals(X_C_Order.PAYMENTRULE_OnCredit)) { newC_PaymentTerm_ID = inputs.cmbPTerm; } // S (Check) (Currency) CheckNo, Routing else if (newPaymentRule.Equals(X_C_Order.PAYMENTRULE_Check)) { // cmbSCurrency.SelectedItem; newC_BankAccount_ID = inputs.cmbSBankAccount; } else { return(details); } SetPayments(inputs._C_Payment_ID, inputs._C_Currency_ID, inputs._PaymentRule); // find Bank Account if not qualified yet if ("KTSD".IndexOf(newPaymentRule) != -1 && newC_BankAccount_ID == 0) { String tender = MPayment.TENDERTYPE_CreditCard; if (newPaymentRule.Equals(MOrder.PAYMENTRULE_DirectDeposit)) { tender = MPayment.TENDERTYPE_DirectDeposit; } else if (newPaymentRule.Equals(MOrder.PAYMENTRULE_DirectDebit)) { tender = MPayment.TENDERTYPE_DirectDebit; } else if (newPaymentRule.Equals(MOrder.PAYMENTRULE_Check)) { tender = MPayment.TENDERTYPE_Check; } } /*********************** * Changed PaymentRule */ if (!newPaymentRule.Equals(inputs._PaymentRule)) { //log.fine("Changed PaymentRule: " + _PaymentRule + " -> " + newPaymentRule); // We had a CashBook Entry if (inputs._PaymentRule.Equals(X_C_Order.PAYMENTRULE_Cash)) { //log.fine("Old Cash - " + _cashLine); if (_cashLine != null) { MCashLine cl = _cashLine.CreateReversal(); if (cl.Save()) { // log.Config("CashCancelled"); } else { errorMsg.Append(Msg.GetMsg(ctx, "CashNotCancelled", true) + Environment.NewLine); // ShowMessage.Error("", true, Msg.GetMsg(Envs.GetContext(), "CashNotCancelled", true).ToString()); } } newC_CashLine_ID = 0; // reset } // We had a change in Payment type (e.g. Check to CC) else if ("KTSD".IndexOf(_PaymentRule) != -1 && "KTSD".IndexOf(newPaymentRule) != -1 && _mPaymentOriginal != null) { //log.fine("Old Payment(1) - " + _mPaymentOriginal); _mPaymentOriginal.SetDocAction(DocActionVariables.ACTION_REVERSE_CORRECT); bool ok = _mPaymentOriginal.ProcessIt(DocActionVariables.ACTION_REVERSE_CORRECT); _mPaymentOriginal.Save(); if (ok) { // log.Info("Payment Canecelled - " + _mPaymentOriginal); } else { errorMsg.Append("PaymentError---" + Msg.GetMsg(ctx, "PaymentNotCancelled", true) + Environment.NewLine); // ShowMessage.Error("", true, "PaymentError" + Msg.GetMsg(Envs.GetContext(), "PaymentNotCancelled", true).ToString() + _mPaymentOriginal.GetDocumentNo()); } _mPayment.ReSetNew(); } // We had a Payment and something else (e.g. Check to Cash) else if ("KTSD".IndexOf(_PaymentRule) != -1 && "KTSD".IndexOf(newPaymentRule) == -1) { //log.fine("Old Payment(2) - " + _mPaymentOriginal); if (_mPaymentOriginal != null) { _mPaymentOriginal.SetDocAction(DocActionVariables.ACTION_REVERSE_CORRECT); bool ok = _mPaymentOriginal.ProcessIt(DocActionVariables.ACTION_REVERSE_CORRECT); _mPaymentOriginal.Save(); if (ok) // Cancel Payment { ///log.Fine("PaymentCancelled " + _mPayment.GetDocumentNo()); //_mTab.getTableModel().dataSave(true); // DataRow datarow = null; // _mTab.GetTableObj().DataSave(true, datarow);//**********************************2nd parameter _mPayment.ReSetNew(); _mPayment.SetAmount(inputs._C_Currency_ID, inputs._Amount); } else { errorMsg.Append("PaymentError---" + Msg.GetMsg(ctx, "PaymentNotCancelled", true) + _mPayment.GetDocumentNo() + Environment.NewLine); //ShowMessage.Error("", true, "PaymentError" + Msg.GetMsg(Envs.GetContext(), "PaymentNotCancelled", true).ToString() + _mPayment.GetDocumentNo()); } } } } // Get Order and optionally Invoice //int C_Order_ID = ctx.GetContextAsInt(inputs.WindowNo, "C_Order_ID"); //int C_Invoice_ID = ctx.GetContextAsInt(inputs.WindowNo, "C_Invoice_ID"); if (inputs.C_Invoice_ID == 0 && inputs._DocStatus.Equals("CO")) { inputs.C_Invoice_ID = GetInvoiceID(inputs.C_Order_ID); } // Amount sign negative, if ARC (Credit Memo) or API (AP Invoice) bool negateAmt = false; MInvoice invoice = null; if (inputs.C_Invoice_ID != 0) { invoice = new MInvoice(ctx, inputs.C_Invoice_ID, null); negateAmt = invoice.IsCreditMemo(); } MOrder order = null; if (invoice == null && inputs.C_Order_ID != 0) { order = new MOrder(ctx, inputs.C_Order_ID, null); } Decimal payAmount = inputs._Amount; if (negateAmt) { payAmount = Decimal.Negate(inputs._Amount);//.negate(); } // Info // log.Config("C_Order_ID=" + C_Order_ID + ", C_Invoice_ID=" + C_Invoice_ID + ", NegateAmt=" + negateAmt); /*********************** * CashBook */ if (newPaymentRule.Equals(X_C_Order.PAYMENTRULE_Cash)) { //log.fine("Cash"); String description = inputs.Description; if (inputs.C_Invoice_ID == 0 && order == null) { //log.Config("No Invoice!"); // ShowMessage.Error("", true, "PaymentError" + Msg.GetMsg(Envs.GetContext(), "CashNotCreated", true).ToString()); errorMsg.Append("PaymentError---" + Msg.GetMsg(ctx, "CashNotCreated", true) + Environment.NewLine); } else { // Changed Amount if (inputs._C_CashLine_ID > 0) { _cashLine = new MCashLine(ctx, inputs._C_CashLine_ID, null); } if (_cashLine != null && payAmount.CompareTo(_cashLine.GetAmount()) != 0) { // log.Config("Changed CashBook Amount"); _cashLine.SetAmount(payAmount); if (_cashLine.Save()) { // log.Config("CashAmt Changed"); } } // Different Date/CashBook if (_cashLine != null && (newC_CashBook_ID != inputs._C_CashBook_ID || !TimeUtil.IsSameDay(_cashLine.GetStatementDate(), newDateAcct))) { //log.Config("Changed CashBook/Date: " + _C_CashBook_ID + "->" + newC_CashBook_ID); MCashLine reverse = _cashLine.CreateReversal(); if (!reverse.Save()) { errorMsg.Append("PaymentError---" + Msg.GetMsg(ctx, "CashNotCancelled", true) + Environment.NewLine); //ShowMessage.Error("", true, "PaymentError" + Msg.GetMsg(Envs.GetContext(), "CashNotCancelled", true).ToString()); } _cashLine = null; } // Create new if (_cashLine == null) { // log.Config("New CashBook"); int C_Currency_ID = 0; if (invoice != null) { C_Currency_ID = invoice.GetC_Currency_ID(); } if (C_Currency_ID == 0 && order != null) { C_Currency_ID = order.GetC_Currency_ID(); } MCash cash = null; if (newC_CashBook_ID != 0) { cash = MCash.Get(ctx, newC_CashBook_ID, newDateAcct, null); } else // Default { cash = MCash.Get(ctx, inputs._AD_Org_ID, newDateAcct, C_Currency_ID, null); } if (cash == null || cash.Get_ID() == 0) { errorMsg.Append("PaymentError---" + Msg.GetMsg(ctx, "CashNotCreated", true) + Environment.NewLine); //ShowMessage.Error("", true, "PaymentError" + Msg.GetMsg(Envs.GetContext(), "CashNotCreated", true).ToString()); } else { MCashLine cl = new MCashLine(cash); if (invoice != null) { cl.SetInvoice(invoice); } if (order != null) { cl.SetOrder(order, null); //_needSave = true; } if (cl.Save()) { //log.Config("CashCreated"); } else { errorMsg.Append("PaymentError---" + Msg.GetMsg(ctx, "CashNotCreated", true) + Environment.NewLine); //ShowMessage.Error("", true, "PaymentError" + Msg.GetMsg(Envs.GetContext(), "CashNotCreated", true).ToString()); } } } } // have invoice } /*********************** * Payments */ if ("KS".IndexOf(newPaymentRule) != -1) { //log.fine("Payment - " + newPaymentRule); // Set Amount _mPayment.SetAmount(inputs._C_Currency_ID, payAmount); if (newPaymentRule.Equals(MOrder.PAYMENTRULE_CreditCard)) { _mPayment.SetCreditCard(MPayment.TRXTYPE_Sales, newCCType, inputs.txtKNumber, "", inputs.txtKExp); _mPayment.SetPaymentProcessor(); } else if (newPaymentRule.Equals(MOrder.PAYMENTRULE_Check)) { _mPayment.SetBankCheck(newC_BankAccount_ID, inputs._isSOTrx, inputs.txtSRouting, inputs.txtSNumber, inputs.txtSCheck); } _mPayment.SetC_BPartner_ID(inputs._C_BPartner_ID); _mPayment.SetC_Invoice_ID(inputs.C_Invoice_ID); if (order != null) { _mPayment.SetC_Order_ID(inputs.C_Order_ID); // _needSave = true; } _mPayment.SetDateTrx(DateTime.SpecifyKind(Convert.ToDateTime(inputs._DateAcct), DateTimeKind.Utc)); _mPayment.SetDateAcct(DateTime.SpecifyKind(Convert.ToDateTime(inputs._DateAcct), DateTimeKind.Utc)); _mPayment.Save(); // Save/Post if (MPayment.DOCSTATUS_Drafted.Equals(_mPayment.GetDocStatus())) { bool ok = _mPayment.ProcessIt(DocActionVariables.ACTION_COMPLETE); _mPayment.Save(); if (ok) { SucessMsg = _mPayment.GetDocumentNo().ToString() + Msg.GetMsg(ctx, "PaymentCreated"); //ShowMessage.Info(_mPayment.GetDocumentNo().ToString(), true, "PaymentCreated", ""); } else { errorMsg.Append("PaymentError---" + Msg.GetMsg(ctx, "PaymentNotCreated", true) + Environment.NewLine); //ShowMessage.Error("", true, "PaymentError" + Msg.GetMsg(Envs.GetContext(), "PaymentNotCreated", true).ToString()); } } else { // log.Fine("NotDraft " + _mPayment); } } if (details == null) { details = new TabDetails(); } details.newPaymentRule = newPaymentRule; details.newDateAcct = newDateAcct; details._C_CashLine_ID = inputs._C_CashLine_ID; details._C_Payment_ID = inputs._C_Payment_ID; details.newC_PaymentTerm_ID = inputs.cmbPTerm; details.ErrorMsg = errorMsg.ToString(); details.SucessMsg = SucessMsg; } catch { } return(details); }
protected override string DoIt() { try { _log.Info("Start Imported Data completion for GulfOil : " + System.DateTime.Now); #region complete Order Record sql.Clear(); sql.Append("SELECT * FROM C_Order WHERE IsActive = 'Y' AND DocStatus NOT IN ('CO' , 'CL') ORDER BY dateacct"); dsRecord = DB.ExecuteDataset(sql.ToString(), null, Get_Trx()); dataRow = dsRecord.Tables[0].Select("IsActive = 'Y' ", "dateacct"); if (dataRow != null && dataRow.Length > 0) { ViennaAdvantage.Model.MOrder order = null; message.Clear(); notCompletedRecord.Clear(); message.Append("Records Of C_Order "); for (int i = 0; i < dataRow.Length; i++) { try { order = new ViennaAdvantage.Model.MOrder(GetCtx(), Util.GetValueOfInt(dataRow[i]["C_Order_ID"]), Get_Trx()); order.CompleteIt(); if (order.GetDocAction() == "CL") { order.SetDocStatus("CO"); order.SetDocAction("CL"); if (!order.Save(Get_Trx())) { notCompletedRecord.Append(order.GetDocumentNo() + " ,"); Get_Trx().Rollback(); ValueNamePair pp = VLogger.RetrieveError(); _log.Info("Error found for saving C_Order Record ID = " + order.GetDocumentNo() + " Error Name is " + pp.GetName() + " And Error Type is " + pp.GetType()); } else { Get_Trx().Commit(); } } else { notCompletedRecord.Append(order.GetDocumentNo() + " ,"); Get_Trx().Rollback(); _log.Info("Order not completed for this Record ID = " + order.GetDocumentNo()); } } catch { } } if (!string.IsNullOrEmpty(notCompletedRecord.ToString())) { errorMessage.Append(message.ToString() + " : " + notCompletedRecord.ToString()); } } #endregion #region complete Invoice Record sql.Clear(); sql.Append("SELECT * FROM C_Invoice WHERE IsActive = 'Y' AND DocStatus NOT IN ('CO' , 'CL') ORDER BY dateacct"); dsRecord = DB.ExecuteDataset(sql.ToString(), null, Get_Trx()); dataRow = dsRecord.Tables[0].Select("IsActive = 'Y' ", "dateacct"); if (dataRow != null && dataRow.Length > 0) { ViennaAdvantage.Model.MInvoice invoice = null; message.Clear(); notCompletedRecord.Clear(); message.Append("Records Of C_Invoice "); for (int i = 0; i < dataRow.Length; i++) { try { invoice = new ViennaAdvantage.Model.MInvoice(GetCtx(), Util.GetValueOfInt(dataRow[i]["C_Invoice_ID"]), Get_Trx()); invoice.CompleteIt(); if (invoice.GetDocAction() == "CL") { invoice.SetDocStatus("CO"); invoice.SetDocAction("CL"); if (!invoice.Save(Get_Trx())) { notCompletedRecord.Append(invoice.GetDocumentNo() + " ,"); Get_Trx().Rollback(); ValueNamePair pp = VLogger.RetrieveError(); _log.Info("Error found for saving C_Invoice Record ID = " + invoice.GetDocumentNo() + " Error Name is " + pp.GetName() + " And Error Type is " + pp.GetType()); } else { Get_Trx().Commit(); } } else { notCompletedRecord.Append(invoice.GetDocumentNo() + " ,"); Get_Trx().Rollback(); _log.Info("Invoice not completed for this Record ID = " + invoice.GetDocumentNo() + " Message- " + invoice.GetProcessMsg()); } } catch { } } if (!string.IsNullOrEmpty(notCompletedRecord.ToString())) { errorMessage.Append(message.ToString() + " : " + notCompletedRecord.ToString()); } } #endregion sql.Clear(); sql.Append("SELECT * FROM M_InOut WHERE IsActive = 'Y' AND DocStatus NOT IN ('CO' , 'CL' , 'RE' , 'VO') ORDER BY movementdate"); dsInOut = DB.ExecuteDataset(sql.ToString(), null, Get_Trx()); sql.Clear(); sql.Append("SELECT * FROM M_Inventory WHERE IsActive = 'Y' AND DocStatus NOT IN ('CO' , 'CL' , 'RE' , 'VO') ORDER BY movementdate"); dsInventory = DB.ExecuteDataset(sql.ToString(), null, Get_Trx()); sql.Clear(); sql.Append("SELECT * FROM M_Movement WHERE IsActive = 'Y' AND DocStatus NOT IN ('CO' , 'CL' , 'RE' , 'VO') ORDER BY movementdate"); dsMovement = DB.ExecuteDataset(sql.ToString(), null, Get_Trx()); sql.Clear(); sql.Append("SELECT * FROM C_Payment WHERE IsActive = 'Y' AND DocStatus NOT IN ('CO' , 'CL' , 'RE' , 'VO') ORDER BY dateacct"); dsPayment = DB.ExecuteDataset(sql.ToString(), null, Get_Trx()); sql.Clear(); sql.Append("SELECT * FROM C_Cash WHERE IsActive = 'Y' AND DocStatus NOT IN ('CO' , 'CL' , 'RE' , 'VO') ORDER BY dateacct"); dsCashJournal = DB.ExecuteDataset(sql.ToString(), null, Get_Trx()); sql.Clear(); sql.Append("SELECT * FROM GL_Journal WHERE IsActive = 'Y' AND DocStatus NOT IN ('CO' , 'CL' , 'RE' , 'VO') ORDER BY dateacct"); dsGLJournal = DB.ExecuteDataset(sql.ToString(), null, Get_Trx()); // min date record from the transaction window minDateRecord = SerachMinDate(); int diff = (DateTime.Now - minDateRecord.Value).Days; for (int days = 0; days <= diff; days++) { if (days != 0) { minDateRecord = minDateRecord.Value.AddDays(1); } try { #region Physical Inventory dataRow = dsInventory.Tables[0].Select("isinternaluse = 'N' AND movementdate = '" + minDateRecord + "'", "M_Inventory_ID"); if (dataRow != null && dataRow.Length > 0) { MInventory inventory = null; message.Clear(); notCompletedRecord.Clear(); message.Append("Records Of Physical Inventory "); for (int i = 0; i < dataRow.Length; i++) { try { inventory = new MInventory(GetCtx(), Util.GetValueOfInt(dataRow[i]["M_Inventory_ID"]), Get_Trx()); inventory.CompleteIt(); if (inventory.GetDocAction() == "CL") { inventory.SetDocStatus("CO"); inventory.SetDocAction("CL"); if (!inventory.Save(Get_Trx())) { notCompletedRecord.Append(inventory.GetDocumentNo() + " ,"); Get_Trx().Rollback(); ValueNamePair pp = VLogger.RetrieveError(); _log.Info("Error found for saving Physical Inventory Record ID = " + inventory.GetDocumentNo() + " Error Name is " + pp.GetName() + " And Error Type is " + pp.GetType()); } else { Get_Trx().Commit(); } } else { notCompletedRecord.Append(inventory.GetDocumentNo() + " ,"); Get_Trx().Rollback(); _log.Info("Physical Inventory not completed for this Record ID = " + inventory.GetDocumentNo()); } } catch { } } if (!string.IsNullOrEmpty(notCompletedRecord.ToString())) { errorMessage.Append(message.ToString() + " : " + notCompletedRecord.ToString()); } } #endregion #region Internal use inventory dataRow = dsInventory.Tables[0].Select("isinternaluse = 'Y' AND movementdate = '" + minDateRecord + "'", "M_Inventory_ID"); if (dataRow != null && dataRow.Length > 0) { MInventory inventory = null; message.Clear(); notCompletedRecord.Clear(); message.Append("Records Of Internal use inventory "); for (int i = 0; i < dataRow.Length; i++) { try { inventory = new MInventory(GetCtx(), Util.GetValueOfInt(dataRow[i]["M_Inventory_ID"]), Get_Trx()); inventory.CompleteIt(); if (inventory.GetDocAction() == "CL") { inventory.SetDocStatus("CO"); inventory.SetDocAction("CL"); if (!inventory.Save(Get_Trx())) { notCompletedRecord.Append(inventory.GetDocumentNo() + " ,"); Get_Trx().Rollback(); ValueNamePair pp = VLogger.RetrieveError(); _log.Info("Error found for saving Physical Inventory Record ID = " + inventory.GetDocumentNo() + " Error Name is " + pp.GetName() + " And Error Type is " + pp.GetType()); } else { Get_Trx().Commit(); } } else { notCompletedRecord.Append(inventory.GetDocumentNo() + " ,"); Get_Trx().Rollback(); _log.Info("Physical Inventory not completed for this Record ID = " + inventory.GetDocumentNo()); } } catch { } } if (!string.IsNullOrEmpty(notCompletedRecord.ToString())) { errorMessage.Append(message.ToString() + " : " + notCompletedRecord.ToString()); } } #endregion #region complete material receipt dataRow = dsInOut.Tables[0].Select("IsSoTrx = 'N' AND IsReturnTrx = 'N' AND DocStatus NOT IN ('CO' , 'CL') AND DateAcct = '" + minDateRecord + "'", "M_InOut_ID"); if (dataRow != null && dataRow.Length > 0) { message.Clear(); notCompletedRecord.Clear(); message.Append("Records Of material receipt "); for (int i = 0; i < dataRow.Length; i++) { try { inout = new ViennaAdvantage.Model.MInOut(GetCtx(), Util.GetValueOfInt(dataRow[i]["M_InOut_ID"]), Get_Trx()); inout.CompleteIt(); if (inout.GetDocAction() == "CL") { inout.SetDocStatus("CO"); inout.SetDocAction("CL"); if (!inout.Save(Get_Trx())) { notCompletedRecord.Append(inout.GetDocumentNo() + " ,"); Get_Trx().Rollback(); ValueNamePair pp = VLogger.RetrieveError(); _log.Info("Error found for saving C_Order Record ID = " + inout.GetDocumentNo() + " Error Name is " + pp.GetName() + " And Error Type is " + pp.GetType()); } else { Get_Trx().Commit(); } } else { notCompletedRecord.Append(inout.GetDocumentNo() + " ,"); Get_Trx().Rollback(); _log.Info("Material Receipt not completed for this Record ID = " + inout.GetDocumentNo()); } } catch { } } if (!string.IsNullOrEmpty(notCompletedRecord.ToString())) { errorMessage.Append(message.ToString() + " : " + notCompletedRecord.ToString()); } } #endregion #region complete Movement Record dataRow = dsMovement.Tables[0].Select("movementdate = '" + minDateRecord + "'", "M_Movement_ID"); if (dataRow != null && dataRow.Length > 0) { ViennaAdvantage.Model.MMovement movement = null; message.Clear(); notCompletedRecord.Clear(); message.Append("Records Of M_Movement "); for (int i = 0; i < dataRow.Length; i++) { try { movement = new ViennaAdvantage.Model.MMovement(GetCtx(), Util.GetValueOfInt(dataRow[i]["M_Movement_ID"]), Get_Trx()); movement.CompleteIt(); if (movement.GetDocAction() == "CL") { movement.SetDocStatus("CO"); movement.SetDocAction("CL"); if (!movement.Save(Get_Trx())) { notCompletedRecord.Append(movement.GetDocumentNo() + " ,"); Get_Trx().Rollback(); ValueNamePair pp = VLogger.RetrieveError(); _log.Info("Error found for saving C_Invoice Record ID = " + movement.GetDocumentNo() + " Error Name is " + pp.GetName() + " And Error Type is " + pp.GetType()); } else { Get_Trx().Commit(); } } else { notCompletedRecord.Append(movement.GetDocumentNo() + " ,"); Get_Trx().Rollback(); _log.Info("Movement not completed for this Record ID = " + movement.GetDocumentNo()); } } catch { } } if (!string.IsNullOrEmpty(notCompletedRecord.ToString())) { errorMessage.Append(message.ToString() + " : " + notCompletedRecord.ToString()); } } #endregion #region complete shipment dataRow = dsInOut.Tables[0].Select("IsSoTrx = 'Y' AND IsReturnTrx = 'N' AND DateAcct = '" + minDateRecord + "'", "M_Inout_ID"); if (dataRow != null && dataRow.Length > 0) { message.Clear(); notCompletedRecord.Clear(); message.Append("Records Of shipment "); for (int i = 0; i < dataRow.Length; i++) { try { inout = new ViennaAdvantage.Model.MInOut(GetCtx(), Util.GetValueOfInt(dataRow[i]["M_InOut_ID"]), Get_Trx()); inout.CompleteIt(); if (inout.GetDocAction() == "CL") { inout.SetDocStatus("CO"); inout.SetDocAction("CL"); if (!inout.Save(Get_Trx())) { notCompletedRecord.Append(inout.GetDocumentNo() + " ,"); Get_Trx().Rollback(); ValueNamePair pp = VLogger.RetrieveError(); _log.Info("Error found for saving C_Order Record ID = " + inout.GetDocumentNo() + " Error Name is " + pp.GetName() + " And Error Type is " + pp.GetType()); } else { Get_Trx().Commit(); } } else { notCompletedRecord.Append(inout.GetDocumentNo() + " ,"); Get_Trx().Rollback(); _log.Info("Shipment not completed for this Record ID = " + inout.GetDocumentNo()); } } catch { } } if (!string.IsNullOrEmpty(notCompletedRecord.ToString())) { errorMessage.Append(message.ToString() + " : " + notCompletedRecord.ToString()); } } #endregion #region complete Customer Return dataRow = dsInOut.Tables[0].Select("IsSoTrx = 'Y' AND IsReturnTrx = 'Y' AND DateAcct = '" + minDateRecord + "'", "M_Inout_ID"); if (dataRow != null && dataRow.Length > 0) { message.Clear(); notCompletedRecord.Clear(); message.Append("Records Of Customer Return "); for (int i = 0; i < dataRow.Length; i++) { try { inout = new ViennaAdvantage.Model.MInOut(GetCtx(), Util.GetValueOfInt(dataRow[i]["M_InOut_ID"]), Get_Trx()); inout.CompleteIt(); if (inout.GetDocAction() == "CL") { inout.SetDocStatus("CO"); inout.SetDocAction("CL"); if (!inout.Save(Get_Trx())) { notCompletedRecord.Append(inout.GetDocumentNo() + " ,"); Get_Trx().Rollback(); ValueNamePair pp = VLogger.RetrieveError(); _log.Info("Error found for saving C_Order Record ID = " + inout.GetDocumentNo() + " Error Name is " + pp.GetName() + " And Error Type is " + pp.GetType()); } else { Get_Trx().Commit(); } } else { notCompletedRecord.Append(inout.GetDocumentNo() + " ,"); Get_Trx().Rollback(); _log.Info("Customer return not completed for this Record ID = " + inout.GetDocumentNo()); } } catch { } } if (!string.IsNullOrEmpty(notCompletedRecord.ToString())) { errorMessage.Append(message.ToString() + " : " + notCompletedRecord.ToString()); } } #endregion #region complete Return to Vendor dataRow = dsInOut.Tables[0].Select("IsSoTrx = 'N' AND IsReturnTrx = 'Y' AND DateAcct = '" + minDateRecord + "'", "M_InOut_ID"); if (dataRow != null && dataRow.Length > 0) { message.Clear(); notCompletedRecord.Clear(); message.Append("Records Of Return to Vendor "); for (int i = 0; i < dataRow.Length; i++) { try { inout = new ViennaAdvantage.Model.MInOut(GetCtx(), Util.GetValueOfInt(dataRow[i]["M_InOut_ID"]), Get_Trx()); inout.CompleteIt(); if (inout.GetDocAction() == "CL") { inout.SetDocStatus("CO"); inout.SetDocAction("CL"); if (!inout.Save(Get_Trx())) { notCompletedRecord.Append(inout.GetDocumentNo() + " ,"); Get_Trx().Rollback(); ValueNamePair pp = VLogger.RetrieveError(); _log.Info("Error found for saving C_Order Record ID = " + inout.GetDocumentNo() + " Error Name is " + pp.GetName() + " And Error Type is " + pp.GetType()); } else { Get_Trx().Commit(); } } else { notCompletedRecord.Append(inout.GetDocumentNo() + " ,"); Get_Trx().Rollback(); _log.Info("Return to Vendor not completed for this Record ID = " + inout.GetDocumentNo()); } } catch { } } if (!string.IsNullOrEmpty(notCompletedRecord.ToString())) { errorMessage.Append(message.ToString() + " : " + notCompletedRecord.ToString()); } } #endregion #region Complete Payment dataRow = dsPayment.Tables[0].Select("DateAcct = '" + minDateRecord + "'", "C_Payment_ID"); if (dataRow != null && dataRow.Length > 0) { message.Clear(); notCompletedRecord.Clear(); message.Append("Records Of Payment "); for (int i = 0; i < dataRow.Length; i++) { try { payment = new MPayment(GetCtx(), Util.GetValueOfInt(dataRow[i]["C_Payment_ID"]), Get_Trx()); payment.CompleteIt(); if (payment.GetDocAction() == "CL") { payment.SetDocStatus("CO"); payment.SetDocAction("CL"); if (!payment.Save(Get_Trx())) { notCompletedRecord.Append(payment.GetDocumentNo() + " ,"); Get_Trx().Rollback(); ValueNamePair pp = VLogger.RetrieveError(); _log.Info("Error found for saving C_Payment Record ID = " + payment.GetDocumentNo() + " Error Name is " + pp.GetName() + " And Error Type is " + pp.GetType()); } else { Get_Trx().Commit(); } } else { notCompletedRecord.Append(payment.GetDocumentNo() + " ,"); Get_Trx().Rollback(); _log.Info("Payment not completed for this Record ID = " + payment.GetDocumentNo()); } } catch { } } if (!string.IsNullOrEmpty(notCompletedRecord.ToString())) { errorMessage.Append(message.ToString() + " : " + notCompletedRecord.ToString()); } } #endregion #region Complete Cash Journal dataRow = dsCashJournal.Tables[0].Select("DateAcct = '" + minDateRecord + "'", "C_Cash_ID"); if (dataRow != null && dataRow.Length > 0) { message.Clear(); notCompletedRecord.Clear(); message.Append("Records Of Cash Journal "); for (int i = 0; i < dataRow.Length; i++) { try { cash = new MCash(GetCtx(), Util.GetValueOfInt(dataRow[i]["C_Cash_ID"]), Get_Trx()); cash.CompleteIt(); if (cash.GetDocAction() == "CL") { cash.SetDocStatus("CO"); cash.SetDocAction("CL"); if (!cash.Save(Get_Trx())) { notCompletedRecord.Append(cash.GetDocumentNo() + " ,"); Get_Trx().Rollback(); ValueNamePair pp = VLogger.RetrieveError(); _log.Info("Error found for saving C_Cash Record ID = " + cash.GetDocumentNo() + " Error Name is " + pp.GetName() + " And Error Type is " + pp.GetType()); } else { Get_Trx().Commit(); } } else { notCompletedRecord.Append(cash.GetDocumentNo() + " ,"); Get_Trx().Rollback(); _log.Info("Cash Journal not completed for this Record ID = " + cash.GetDocumentNo()); } } catch { } } if (!string.IsNullOrEmpty(notCompletedRecord.ToString())) { errorMessage.Append(message.ToString() + " : " + notCompletedRecord.ToString()); } } #endregion #region Complete GL Journal dataRow = dsGLJournal.Tables[0].Select("DateAcct = '" + minDateRecord + "'", "GL_Journal_ID"); if (dataRow != null && dataRow.Length > 0) { message.Clear(); notCompletedRecord.Clear(); message.Append("Records Of GL Journal "); for (int i = 0; i < dataRow.Length; i++) { try { journal = new MJournal(GetCtx(), Util.GetValueOfInt(dataRow[i]["GL_Journal_ID"]), Get_Trx()); journal.CompleteIt(); if (journal.GetDocAction() == "CL") { journal.SetDocStatus("CO"); journal.SetDocAction("CL"); if (!journal.Save(Get_Trx())) { notCompletedRecord.Append(journal.GetDocumentNo() + " ,"); Get_Trx().Rollback(); ValueNamePair pp = VLogger.RetrieveError(); _log.Info("Error found for saving C_Cash Record ID = " + journal.GetDocumentNo() + " Error Name is " + pp.GetName() + " And Error Type is " + pp.GetType()); } else { Get_Trx().Commit(); } } else { notCompletedRecord.Append(journal.GetDocumentNo() + " ,"); Get_Trx().Rollback(); _log.Info("Cash Journal not completed for this Record ID = " + journal.GetDocumentNo()); } } catch { } } if (!string.IsNullOrEmpty(notCompletedRecord.ToString())) { errorMessage.Append(message.ToString() + " : " + notCompletedRecord.ToString()); } } #endregion } catch { } } _log.Info(" End Imported Data completion for GulfOil : " + System.DateTime.Now); } catch (Exception ex) { _log.Info("Error Occured during completion of record by using ImportedDataCompletion Process - " + ex.ToString()); return(Msg.GetMsg(GetCtx(), "NotCompleted")); } if (!string.IsNullOrEmpty(errorMessage.ToString())) { return("Not Completed Record : " + errorMessage.ToString()); } else { return(Msg.GetMsg(GetCtx(), "SucessfullyCompleted")); } }
protected override string DoIt() { MCash cashheader = new MCash(GetCtx(), GetRecord_ID(), Get_Trx()); sql = "select C_Currency_ID from C_CashBook where c_Cashbook_id=" + cashheader.GetC_CashBook_ID(); int C_Currencyheader_ID = Util.GetValueOfInt(DB.ExecuteScalar(sql, null, Get_Trx())); sql = "select * from C_Cashline WHERE C_Cash_ID=" + GetRecord_ID(); DataSet dscashline = DB.ExecuteDataset(sql, null, Get_Trx()); if (dscashline != null) { if (dscashline.Tables[0].Rows.Count > 0) { for (i = 0; i < dscashline.Tables[0].Rows.Count; i++) { cashline = new MCashLine(GetCtx(), Util.GetValueOfInt(dscashline.Tables[0].Rows[i]["C_CashLine_ID"]), Get_Trx()); if (cashline.GetCashType().ToString() == "A" || cashline.GetCashType().ToString() == "F") { sql = "Select * from C_Cash where C_CashBook_Id=" + cashline.GetC_CashBook_ID() + " and docstatus='DR' and DateAcct=" + GlobalVariable.TO_DATE(DateTime.Now, true); DataSet dscashbook = DB.ExecuteDataset(sql, null, Get_Trx()); if (dscashbook != null) { if (dscashbook.Tables[0].Rows.Count > 0) { int j; for (j = 0; j < dscashbook.Tables[0].Rows.Count; j++) { cash = new MCash(GetCtx(), Util.GetValueOfInt(dscashbook.Tables[0].Rows[j]["C_Cash_ID"]), Get_Trx()); if (!_cashIds.Contains(cash.GetC_Cash_ID())) { _cashIds.Add(cash.GetC_Cash_ID()); } //ViennaAdvantage.Model.MCashLine cashline1 = new ViennaAdvantage.Model.MCashLine(GetCtx(), 0, Get_Trx()); MCashLine cashline1 = new MCashLine(GetCtx(), 0, Get_Trx()); cashline1.SetC_Cash_ID(cash.GetC_Cash_ID()); cashline1.SetAD_Client_ID(cash.GetAD_Client_ID()); cashline1.SetAD_Org_ID(cash.GetAD_Org_ID()); if (cashline.GetCashType().ToString() == "A") { cashline1.SetCashType("F"); } if (cashline.GetCashType().ToString() == "F") { cashline1.SetCashType("A"); } cashline1.SetC_CashBook_ID(cashheader.GetC_CashBook_ID()); cashline1.SetC_BPartner_ID(cashline.GetC_BPartner_ID()); sql = "select C_Currency_ID from C_CashBook where c_Cashbook_id=" + cash.GetC_CashBook_ID(); Currency_ID = Util.GetValueOfInt(DB.ExecuteScalar(sql, null, Get_Trx())); if (Currency_ID == C_Currencyheader_ID) { cashline1.SetC_Currency_ID(C_Currencyheader_ID); cashline1.SetAmount(Decimal.Negate(cashline.GetAmount())); cashline1.SetConvertedAmt(Util.GetValueOfString(Decimal.Negate(cashline.GetAmount()))); } else { cashline1.SetC_Currency_ID(Currency_ID); sql = "select multiplyrate from c_conversion_rate where isactive='Y' and c_currency_id=" + C_Currencyheader_ID + " and c_currency_to_id=" + Currency_ID; _Curencyrate = Util.GetValueOfDecimal(DB.ExecuteScalar(sql, null, Get_Trx())); if (_Curencyrate == 0) { return(Msg.GetMsg(GetCtx(), "NoCurrencyRateDefined")); } else { convertedamount = Decimal.Round(Decimal.Multiply(_Curencyrate, Decimal.Negate(cashline.GetAmount())), 2); } cashline1.SetConvertedAmt(Util.GetValueOfString(convertedamount)); cashline1.SetAmount(convertedamount); } cashline1.SetC_Charge_ID(cashline.GetC_Charge_ID()); if (cashline.GetCashType().ToString() == "A") { cashline1.SetVSS_PAYMENTTYPE("R"); } if (cashline.GetCashType().ToString() == "F") { cashline1.SetVSS_PAYMENTTYPE("P"); } cashline1.SetC_CashLine_ID_1(cashline.GetC_CashLine_ID()); if (!cashline1.Save()) { Rollback(); log.Severe("NotSaved"); return(" NotSaved Cashline1 [ Header Found ] "); } if (cashline.GetCashType().ToString() == "F") { cashline.SetC_CashLine_ID_1(cashline1.GetC_CashLine_ID()); } if (!cashline.Save()) { Rollback(); log.Severe("Not Saved"); return(" NotSaved Cashline [ Header Found ] "); } int BeginBal = Util.GetValueOfInt(DB.ExecuteScalar("select completedbalance from c_cashbook where c_cashbook_id=" + cash.GetC_CashBook_ID(), null, Get_Trx())); cash.SetBeginningBalance(BeginBal); if (!cash.Save(Get_Trx())) { Rollback(); log.Severe("Not Saved"); return(" NotSaved Cash [ Header Found ] "); } break; } } else { dscashbook.Dispose(); MCash cash1 = new MCash(GetCtx(), 0, Get_Trx()); cash1.SetAD_Client_ID(cashheader.GetAD_Client_ID()); cash1.SetAD_Org_ID(cashheader.GetAD_Org_ID()); cash1.SetC_DocType_ID(cashheader.GetC_DocType_ID()); cash1.SetName(Util.GetValueOfString(System.DateTime.Today.ToShortDateString())); cash1.SetC_CashBook_ID(cashline.GetC_CashBook_ID()); cash1.SetDateAcct(DateTime.Now); cash1.SetStatementDate(DateTime.Now); if (!cash1.Save()) { Rollback(); VAdvantage.Model.ValueNamePair ppE = VLogger.RetrieveError(); if (ppE != null) { return(ppE.GetName() + "<--->" + ppE.GetValue()); } return("cash1 not saved [header not found->]"); } // return cash1.GetC_Cash_ID() + "suc"; if (!_cashIds.Contains(cash1.GetC_Cash_ID())) { _cashIds.Add(cash1.GetC_Cash_ID()); } MCashLine cashline1 = new MCashLine(GetCtx(), 0, Get_Trx()); cashline1.SetC_Cash_ID(cash1.GetC_Cash_ID()); cashline1.SetAD_Client_ID(cash1.GetAD_Client_ID()); cashline1.SetAD_Org_ID(cash1.GetAD_Org_ID()); if (cashline.GetCashType().ToString() == "A") { cashline1.SetCashType("F"); } if (cashline.GetCashType().ToString() == "F") { cashline1.SetCashType("A"); } cashline1.SetC_CashBook_ID(cashheader.GetC_CashBook_ID()); cashline1.SetC_BPartner_ID(cashline.GetC_BPartner_ID()); sql = "select C_Currency_ID from C_CashBook where c_Cashbook_id=" + cash1.GetC_CashBook_ID(); Currency_ID = Util.GetValueOfInt(DB.ExecuteScalar(sql, null, Get_Trx())); if (Currency_ID == C_Currencyheader_ID) { cashline1.SetAmount(Decimal.Negate(cashline.GetAmount())); cashline1.SetC_Currency_ID(C_Currencyheader_ID); cashline1.SetConvertedAmt(Util.GetValueOfString(Decimal.Negate(cashline.GetAmount()))); } else { cashline1.SetC_Currency_ID(Currency_ID); sql = "select multiplyrate from c_conversion_rate where isactive='Y' and c_currency_id=" + C_Currencyheader_ID + " and c_currency_to_id=" + Currency_ID; _Curencyrate = Util.GetValueOfDecimal(DB.ExecuteScalar(sql, null, Get_Trx())); if (_Curencyrate == 0) { return(Msg.GetMsg(GetCtx(), "NoCurrencyRateDefined")); } else { convertedamount = Decimal.Round(Decimal.Multiply(_Curencyrate, Decimal.Negate(cashline.GetAmount())), 2); } cashline1.SetConvertedAmt(Util.GetValueOfString(convertedamount)); cashline1.SetAmount(convertedamount); } cashline1.SetC_Charge_ID(cashline.GetC_Charge_ID()); if (cashline.GetCashType().ToString() == "A") { cashline1.SetVSS_PAYMENTTYPE("R"); } if (cashline.GetCashType().ToString() == "F") { cashline1.SetVSS_PAYMENTTYPE("P"); } cashline1.SetC_CashLine_ID_1(cashline.GetC_CashLine_ID()); if (!cashline1.Save(Get_Trx())) { Rollback(); log.Severe("NotSaved"); return(" NotSaved Cashline1 [ Header not Found ] "); } if (cashline.GetCashType().ToString() == "F") { cashline.SetC_CashLine_ID_1(cashline1.GetC_CashLine_ID()); } if (!cashline.Save(Get_Trx())) { Rollback(); log.Severe("NotSaved"); return(" NotSaved Cashline [ Header not Found ] "); } int BeginBal = Util.GetValueOfInt(DB.ExecuteScalar("select completedbalance from c_cashbook where c_cashbook_id=" + cash1.GetC_CashBook_ID(), null, Get_Trx())); cash1.SetBeginningBalance(BeginBal); if (!cash1.Save()) { Rollback(); log.Severe("NotSaved"); return(" NotSaved Cash1 [ Header not Found(bb) ] "); } } } else { //dscashbook.Dispose(); } } else { cashtype++; } } decimal OpenBal = Util.GetValueOfDecimal(DB.ExecuteScalar("SELECT completedbalance FROM C_CashBook WHERE c_cashbook_id=" + cashheader.GetC_CashBook_ID() + "", null, Get_Trx())); cashheader.SetBeginningBalance(OpenBal); if (!cashheader.Save()) { Rollback(); log.Severe("Not Saved"); } } else { dscashline.Dispose(); cashheader.SetGenerateCashBookTransfer("Y"); if (!cashheader.Save()) { Rollback(); log.Severe("NotSaved"); } return(Msg.GetMsg(GetCtx(), "NoCashLineExist")); } if (_cashIds.Count > 0) { for (int k = 0; k < _cashIds.Count; k++) { cash = new MCash(GetCtx(), _cashIds[k], Get_Trx()); cash.SetDocStatus(cash.CompleteIt()); if (!cash.Save()) { Rollback(); log.Severe("NotSaved"); } } } } cashheader.SetGenerateCashBookTransfer("Y"); if (!cashheader.Save()) { log.Severe("NotSaved"); } if (cashtype == i) { return(Msg.GetMsg(GetCtx(), "NoCashLineExist")); } return("Completed"); }