protected void RadToolBar_ButtonClick(object sender, RadToolBarEventArgs e) { switch (e.Item.Text) { case "TempSave": case "Request": if (IsValid) { var cC = new CCreditMemoPayout(); var c = new Erp2016.Lib.CreditMemoPayout(); // new if (Request["type"] == "0") { c = new Erp2016.Lib.CreditMemoPayout(); c.CreatedId = CurrentUserId; c.CreatedDate = DateTime.Now; c.CreditMemoId = Id; } // modify else { c = cC.Get(Id); } c = CreditMemoPayout1.GetData(c); c.Amount = (decimal)RadNumericTextBoxAmount.Value; c.IsActive = true; c.SiteLocationId = CurrentSiteLocationId; int creditMemoPayoutId; // new if (Request["type"] == "0") { decimal availableAmount = new CCreditMemo().GetAvailableCreditAmount(Id); if (availableAmount >= c.Amount) { decimal originalAmount = new CCreditMemo().GetOriginalCreditAmount(Id); if ((originalAmount - availableAmount) + c.Amount < 0) { ShowMessage("result of available amount can't be negative amount"); } else { creditMemoPayoutId = cC.Add(c); // save file FileDownloadList1.SaveFile(Id); if (e.Item.Text == "TempSave") { RunClientScript("Close();"); } else { if (SetReqeust(creditMemoPayoutId)) { RunClientScript("Close();"); } else { ShowMessage("error requesting"); } } } } else { ShowMessage("paid amount is bigger than available credit amount"); } } // modify else { c.UpdatedId = CurrentUserId; c.UpdatedDate = DateTime.Now; cC.Update(c); creditMemoPayoutId = c.CreditMemoPayoutId; // save file FileDownloadList1.SaveFile(Id); if (SetReqeust(creditMemoPayoutId)) { RunClientScript("Close();"); } else { ShowMessage("error requesting"); } } } break; case "Close": RunClientScript("Close();"); break; } }
protected void ToolbarButtonClick(object sender, RadToolBarEventArgs e) { switch (e.Item.Text) { case "Request": if (IsValid) { var cInvoice = new CInvoice(); var original = cInvoice.Get(InvoiceId); if (original != null) { original.Status = (int)CConstValue.InvoiceStatus.Invoiced_Hold; original.UpdatedId = CurrentUserId; if (cInvoice.Update(original)) { var cRefundInvoice = new CInvoice(); var refundInvoice = new Erp2016.Lib.Invoice(); CGlobal.Copy(original, refundInvoice); refundInvoice.OriginalInvoiceId = original.InvoiceId; switch (original.InvoiceType) { case (int)CConstValue.InvoiceType.General: case (int)CConstValue.InvoiceType.Simple: case (int)CConstValue.InvoiceType.Manual: refundInvoice.InvoiceType = (int)CConstValue.InvoiceType.Refund_RF; break; case (int)CConstValue.InvoiceType.Homestay: refundInvoice.InvoiceType = (int)CConstValue.InvoiceType.Refund_HR; break; case (int)CConstValue.InvoiceType.Dormitory: refundInvoice.InvoiceType = (int)CConstValue.InvoiceType.Refund_DR; break; } refundInvoice.Status = (int)CConstValue.InvoiceStatus.Pending; refundInvoice.CreatedId = CurrentUserId; refundInvoice.CreatedDate = DateTime.Now; var invoiceId = cRefundInvoice.Add(refundInvoice); if (invoiceId > 0) { var refundInvoiceItems = new CInvoiceItem(); refundInvoiceItems.RefundItemsUpdate(original.InvoiceId, invoiceId, Convert.ToDecimal(RefundInfo1.GetRefundRate().Value), CurrentUserId); var cCreditMemo = new CCreditMemo(); var creditMemo = new CreditMemo(); creditMemo.CreditMemoType = (int)CConstValue.CreditMemoType.Refund; creditMemo.InvoiceId = invoiceId; //Refund Invoice Id creditMemo.OriginalCreditMemoAmount = 0; creditMemo.CreatedId = CurrentUserId; creditMemo.CreatedDate = DateTime.Now; creditMemo.IsActive = false; var creditMemoId = cCreditMemo.Add(creditMemo); if (creditMemoId > 0) { var cCreditMemoPayout = new CCreditMemoPayout(); var creditMemoPayout = new CreditMemoPayout(); creditMemoPayout.CreditMemoId = creditMemoId; creditMemoPayout.Amount = 0; creditMemoPayout.IsActive = false; creditMemoPayout.CreatedId = CurrentUserId; creditMemoPayout.CreatedDate = DateTime.Now; var creditMemoPayoutId = cCreditMemoPayout.Add(creditMemoPayout); if (creditMemoPayoutId > 0) { var cRefund = new CRefund(); var refund = new Refund(); refund.CreditMemoPayoutId = creditMemoPayoutId; refund.InvoiceId = invoiceId; refund.RefundDate = Convert.ToDateTime(RefundInfo1.RadActualDate().SelectedDate); refund.RefundRate = Convert.ToDouble(RefundInfo1.GetRefundRate().Value); refund.RefundReason = RefundInfo1.GetReason().Text; refund.IsActive = false; refund.CreatedId = CurrentUserId; refund.CreatedDate = DateTime.Now; if (cRefund.Add(refund) > 0) { // save uploading file FileDownloadList1.SaveFile(refund.RefundId); RunClientScript("Close();"); } ShowMessage("failed to update inqury (Add Refund Info)"); } else { ShowMessage("failed to update inqury (Add CreditMemoPayout)"); } } else { ShowMessage("failed to update inqury (Add CreditMemo)"); } } else { ShowMessage("failed to update inqury (Add Refund Invoice)"); } } else { ShowMessage("failed to update inqury (Update Original Invoice)"); } } else { ShowMessage("failed to update inqury (Original Invoice is null)"); } } break; case "Close": RunClientScript("Close();"); break; } }