private void PrepareDataForUpdate(DataRow dtReceiptDetail_Customer, DataTable dtBatch_Invoice, DateTime run_date) { decimal ALLOCATED_MONEY = 0; decimal.TryParse((dtReceiptDetail_Customer["ALLOCATED_MONEY"] == null ? "" : dtReceiptDetail_Customer["ALLOCATED_MONEY"].ToString()), out ALLOCATED_MONEY); decimal DEPOSIT_AMOUNT = 0; decimal.TryParse((dtReceiptDetail_Customer["DEPOSIT_AMOUNT"] == null ? "" : dtReceiptDetail_Customer["DEPOSIT_AMOUNT"].ToString()), out DEPOSIT_AMOUNT); decimal decAvailableAmount = DEPOSIT_AMOUNT - ALLOCATED_MONEY; int SEQ_NO = 0; int.TryParse((dtReceiptDetail_Customer["SEQ_NO"] == null ? "" : dtReceiptDetail_Customer["SEQ_NO"].ToString()), out SEQ_NO); DateTime DEPOSIT_DATE; DateTime.TryParse((dtReceiptDetail_Customer["DEPOSIT_AMOUNT"] == null ? "" : dtReceiptDetail_Customer["DEPOSIT_DATE"].ToString()), out DEPOSIT_DATE); int ALLOCATED_QUANTITY = 0; int.TryParse((dtReceiptDetail_Customer["ALLOCATED_QUANTITY"] == null ? "" : dtReceiptDetail_Customer["ALLOCATED_QUANTITY"].ToString()), out ALLOCATED_QUANTITY); decimal CalculateForType = 0; if (decAvailableAmount != 0) { BOL_RECEIPT_DETAILS oRECEIPT_DETAILS = new BOL_RECEIPT_DETAILS(); oRECEIPT_DETAILS.ALLOCATED_QUANTITY = ALLOCATED_QUANTITY; oRECEIPT_DETAILS.ALLOCATED_MONEY = ALLOCATED_MONEY; //20201117_追加_ALLOCATED_MONEYを初期値でセット #region Prepare Invoice, Reserve Info and Receipt Detail for (int i = 0; i < dtBatch_Invoice.Rows.Count; i++) { //BILL PRICE decimal BILL_PRICE = 0; decimal.TryParse((dtBatch_Invoice.Rows[i]["BILL_PRICE"] == null ? "" : dtBatch_Invoice.Rows[i]["BILL_PRICE"].ToString()), out BILL_PRICE); //ALLOCATATION TOTAL AMOUNT calculate decimal ALLOCATION_TOTAL_AMOUNT = 0; decimal.TryParse((dtBatch_Invoice.Rows[i]["ALLOCATION_TOTAL_AMOUNT"] == null ? "" : dtBatch_Invoice.Rows[i]["ALLOCATION_TOTAL_AMOUNT"].ToString()), out ALLOCATION_TOTAL_AMOUNT); //BILL TRANSFER FEE decimal BILL_TRANSFER_FEE = 0; decimal.TryParse((dtBatch_Invoice.Rows[i]["BILL_TRANSFER_FEE"] == null ? "" : dtBatch_Invoice.Rows[i]["BILL_TRANSFER_FEE"].ToString()), out BILL_TRANSFER_FEE); string strYear_Month = (dtBatch_Invoice.Rows[i]["YEAR_MONTH"] == null ? "" : dtBatch_Invoice.Rows[i]["YEAR_MONTH"].ToString()); string strCompanyNoBox = (dtBatch_Invoice.Rows[i]["COMPANY_NO_BOX"] == null ? "" : dtBatch_Invoice.Rows[i]["COMPANY_NO_BOX"].ToString()); CalculateForType = BILL_PRICE - ALLOCATION_TOTAL_AMOUNT + BILL_TRANSFER_FEE; CalculateForType = (CalculateForType < 0 ? CalculateForType * -1 : CalculateForType); BOL_RESERVE_INFO oRESERVE_INFO = new BOL_RESERVE_INFO(); BOL_INVOICE_INFO oInvoiceInfo = new BOL_INVOICE_INFO(); if (decAvailableAmount >= CalculateForType) //Type A { //Prepare Update For Invoice oInvoiceInfo.ALLOCATION_TOTAL_AMOUNT = ALLOCATION_TOTAL_AMOUNT + CalculateForType; oInvoiceInfo.ALLOCATED_COMPLETION_DATE = run_date; oInvoiceInfo.YEAR_MONTH = strYear_Month; oInvoiceInfo.COMPANY_NO_BOX = strCompanyNoBox; oInvoiceInfo.TYPE_OF_ALLOCATION = 1; oInvoiceInfo.STATUS_ACTUAL_DEPOSIT_YYMM = DEPOSIT_DATE.ToString("yyMM"); oInvoiceInfo.STATUS_ACTUAL_DEPOSIT_DATE = DEPOSIT_DATE.ToString("yyyy-MM-dd"); lstInvoiceInfo.Add(oInvoiceInfo); //Prepare Insert For Reserve Info oRESERVE_INFO.SEQ_NO = SEQ_NO; oRESERVE_INFO.BILLING_CODE = strCompanyNoBox + strYear_Month; oRESERVE_INFO.PAYMENT_DAY = run_date; oRESERVE_INFO.TYPE_OF_ALLOCATION = 1; oRESERVE_INFO.RESERVE_AMOUNT = CalculateForType; oRESERVE_INFO.DIFF_ALLOCATION_AMOUNT = decAvailableAmount - CalculateForType; lstReserveInfo.Add(oRESERVE_INFO); //Prepare Update for receipt detail oRECEIPT_DETAILS.ALLOCATED_MONEY += CalculateForType; if (DEPOSIT_AMOUNT == oRECEIPT_DETAILS.ALLOCATED_MONEY) { oRECEIPT_DETAILS.ALLOCATED_COMPLETION_DATE = run_date; } oRECEIPT_DETAILS.SEQ_NO = SEQ_NO; oRECEIPT_DETAILS.PAYMENT_DAY = run_date; oRECEIPT_DETAILS.TYPE_OF_ALLOCATION = 1; oRECEIPT_DETAILS.ALLOCATED_QUANTITY += 1; lstReceiptDetail.Add(oRECEIPT_DETAILS); decAvailableAmount = decAvailableAmount - CalculateForType; } else if (decAvailableAmount < CalculateForType) //Type B { //Prepare Update For Invoice Info oInvoiceInfo.ALLOCATION_TOTAL_AMOUNT = ALLOCATION_TOTAL_AMOUNT + decAvailableAmount; if (CalculateForType == 0) { oInvoiceInfo.ALLOCATED_COMPLETION_DATE = run_date; } oInvoiceInfo.YEAR_MONTH = strYear_Month; oInvoiceInfo.COMPANY_NO_BOX = strCompanyNoBox; oInvoiceInfo.TYPE_OF_ALLOCATION = 1; oInvoiceInfo.STATUS_ACTUAL_DEPOSIT_YYMM = DEPOSIT_DATE.ToString("yyMM"); oInvoiceInfo.STATUS_ACTUAL_DEPOSIT_DATE = DEPOSIT_DATE.ToString("yyyy-MM-dd"); lstInvoiceInfo.Add(oInvoiceInfo); //Prepare Insert For Reserve Info oRESERVE_INFO.SEQ_NO = SEQ_NO; oRESERVE_INFO.BILLING_CODE = strCompanyNoBox + strYear_Month; oRESERVE_INFO.PAYMENT_DAY = run_date; oRESERVE_INFO.TYPE_OF_ALLOCATION = 1; oRESERVE_INFO.RESERVE_AMOUNT = decAvailableAmount; oRESERVE_INFO.DIFF_ALLOCATION_AMOUNT = decAvailableAmount - CalculateForType; lstReserveInfo.Add(oRESERVE_INFO); //Prepare Update for Receipt Detail oRECEIPT_DETAILS.ALLOCATED_COMPLETION_DATE = run_date; oRECEIPT_DETAILS.ALLOCATED_MONEY = DEPOSIT_AMOUNT; oRECEIPT_DETAILS.SEQ_NO = SEQ_NO; oRECEIPT_DETAILS.PAYMENT_DAY = run_date; oRECEIPT_DETAILS.TYPE_OF_ALLOCATION = 1; oRECEIPT_DETAILS.ALLOCATED_QUANTITY += 1; lstReceiptDetail.Add(oRECEIPT_DETAILS); decAvailableAmount = decAvailableAmount - CalculateForType; } ALLOCATED_MONEY += oRECEIPT_DETAILS.ALLOCATED_MONEY; if (oRECEIPT_DETAILS.ALLOCATED_COMPLETION_DATE != null) { break; } } #endregion RECEIPT_DETAILS oRCP = new RECEIPT_DETAILS(Properties.Settings.Default.MyConnection); INVOICE_INFO oInv = new INVOICE_INFO(Properties.Settings.Default.MyConnection); RESERVE_INFO oReseve = new RESERVE_INFO(Properties.Settings.Default.MyConnection); string strMessage = ""; for (int i = 0; i < lstReceiptDetail.Count; i++) { oRCP.UpdateReceipt_Detail(lstReceiptDetail[i], out strMessage); } for (int i = 0; i < lstInvoiceInfo.Count; i++) { oInv.UpdateInvoice_Info(lstInvoiceInfo[i], out strMessage); } for (int i = 0; i < lstReserveInfo.Count; i++) { oReseve.insert(lstReserveInfo[i], out strMessage); } } }
public Response CancelAllocation(string strData) { using (TransactionScope dbTxn = new TransactionScope()) { try { string strReturnMsg = ""; string strMSG = ""; DataTable dtData = AmigoProcessManagement.Utility.Utility_Component.JsonToDt(strData); if (dtData.Rows.Count > 0) { for (int i = 0; i < dtData.Rows.Count; i++) { int GRID_SEQ_NO = AmigoProcessManagement.Utility.Utility_Component.dtColumnToInt((dtData.Rows[i]["SEQ_NO"] == null ? "" : dtData.Rows[i]["SEQ_NO"].ToString())); string GRID_COMPANY_NO_BOX = dtData.Rows[i]["COMPANY_NO_BOX"] == null ? "" : dtData.Rows[i]["COMPANY_NO_BOX"].ToString(); string GRID_YEAR_MONTH = dtData.Rows[i]["YEAR_MONTH"] == null ? "" : dtData.Rows[i]["YEAR_MONTH"].ToString(); string GRID_BILLING_CODE = GRID_COMPANY_NO_BOX + GRID_YEAR_MONTH; //getAllocatedAmount RESERVE_INFO oRI = new RESERVE_INFO(Properties.Settings.Default.MyConnection); DataTable dt = oRI.GetReservceInfoByBillingCode(GRID_BILLING_CODE); if (dt.Rows.Count > 0) { for (int j = 0; j < dt.Rows.Count; j++) { //UpdateReceiptDetail RECEIPT_DETAILS oRecep = new RECEIPT_DETAILS(Properties.Settings.Default.MyConnection); int RESERVE_SEQ_NO = int.Parse(dt.Rows[j][0].ToString()); oRecep.CancelAllocation(RESERVE_SEQ_NO, out strMSG); strReturnMsg = strMSG; //GET COMPANY_NO_BOX from Reserve By SEQ_N0 DataTable BILLING_CODES = oRI.GetCompanyNoBoxBySEQNO(RESERVE_SEQ_NO, out strMSG); for (int k = 0; k < BILLING_CODES.Rows.Count; k++) { string MATCHED_BILLING_CODE = BILLING_CODES.Rows[k][0].ToString(); //UpdateInvoiceInfo INVOICE_INFO oINV = new INVOICE_INFO(Properties.Settings.Default.MyConnection); oINV.UpdateInvoiceForCancel(MATCHED_BILLING_CODE.Substring(0, 10), MATCHED_BILLING_CODE.Substring(10, 5), out strMSG); strReturnMsg = strReturnMsg + strMSG; //DeleteReserveInfo strMSG = oRI.removeReserve(RESERVE_SEQ_NO, MATCHED_BILLING_CODE); strReturnMsg = strReturnMsg + strMSG; } } } if (strReturnMsg != "") { break; } } } else { strReturnMsg = "Data Error."; } if (strReturnMsg != "") { dbTxn.Dispose(); //rollback response.Status = 0; } else { dbTxn.Complete(); //commit operation response.Status = 1; } response.Message = strReturnMsg; return(response); } catch (Exception ex) { response.Status = 0; response.Message = ex.Message + "\n" + ex.StackTrace; dbTxn.Dispose(); return(response); } } }