private void button1_Click(object sender, EventArgs e) { if (commissionStatusComboBox.SelectedIndex == -1) { MessageBox.Show("Pilih kategori tuslah !!!", AppCode.AssemblyProduct, MessageBoxButtons.OK, MessageBoxIcon.Information); commissionStatusComboBox.Focus(); return; } MCommission comm = (MCommission)DataMaster.GetObjectByProperty(typeof(MCommission), MCommission.ColumnNames.CommissionStatus, commissionStatusComboBox.SelectedItem.ToString()); if (comm == null) { comm = new MCommission(); } comm.CommissionValue = commissionValueNumericUpDown.Value; comm.CommissionDesc = commissionDescTextBox.Text; comm.CommissionStatus = commissionStatusComboBox.SelectedItem.ToString(); DataMaster.SaveOrUpdate(comm); FillCommissionShareTabPages(comm.CommissionId, true); MessageBox.Show(this.Text + " berhasil disimpan !!", AppCode.AssemblyProduct, MessageBoxButtons.OK, MessageBoxIcon.Information); }
public ActionResult Insert(MCommission viewModel, FormCollection formCollection, string department) { var commission = new MCommission(); TransferFormValuesTo(commission, formCollection); commission.SetAssignedIdTo(Guid.NewGuid().ToString()); commission.CommissionStatus = department; commission.CreatedDate = DateTime.Now; commission.CreatedBy = User.Identity.Name; commission.DataStatus = EnumDataStatus.New.ToString(); _mCommissionRepository.Save(commission); try { _mCommissionRepository.DbContext.CommitChanges(); } catch (Exception e) { _mCommissionRepository.DbContext.RollbackTransaction(); return(Content(e.GetBaseException().Message)); } return(Content("Data Komisi berhasil dimasukkan")); }
private void FillCommissionShareTabPages(decimal CommissionId, bool isSavePosition) { if (isSavePosition && CommissionId == 0) { MCommission comm = (MCommission)DataMaster.GetObjectByProperty(typeof(MCommission), MCommission.ColumnNames.CommissionStatus, commissionStatusComboBox.SelectedItem.ToString()); CommissionId = comm.CommissionId; } Type share = typeof(ListOfCommissionShare); TabPage tab; NumericUpDown num; TextBox txt; MCommissionShare commShare; string shareName; foreach (string s in Enum.GetNames(share)) { shareName = Enum.Parse(share, s).ToString(); commShare = (MCommissionShare)DataMaster.GetObjectByProperty(typeof(MCommissionShare), MCommissionShare.ColumnNames.CommissionId, CommissionId, MCommissionShare.ColumnNames.ShareTo, shareName); if (commShare == null) { commShare = new MCommissionShare(); } tab = tabControl_CommissionShare.TabPages[ControlName.tab_pages_.ToString() + shareName]; //set numeric share value num = (NumericUpDown)tab.Controls[ControlName.num_.ToString() + shareName]; if (isSavePosition) { commShare.ShareValue = num.Value; } else { num.Value = commShare.ShareValue; } //add textboxdesc txt = (TextBox)tab.Controls[ControlName.txt_.ToString() + shareName]; if (isSavePosition) { commShare.ShareDesc = txt.Text; } else { txt.Text = commShare.ShareDesc; } if (isSavePosition) { commShare.CommissionId = CommissionId; commShare.ShareTo = shareName; DataMaster.SaveOrUpdate(commShare); } } }
private void CalculateCommissionSurveyor(TRecPeriod recPeriod, IList <TLoan> listLoan) { MCommission comm = _mCommissionRepository.GetCommissionByDate(EnumDepartment.SU, recPeriod.PeriodFrom, recPeriod.PeriodTo); if (comm == null) { throw new Exception("Data komisi untuk surveyor tidak tersedia."); } IList <MCommissionDet> listDets = comm.CommissionDets; decimal?incentiveSurvey = 0; decimal?incentiveApprove = 0; //get incentive if (listDets.Count > 0) { MCommissionDet det = listDets[0]; incentiveSurvey = det.DetailIncentiveSurveyOnly; incentiveApprove = det.DetailIncentiveSurveyAcc; } //get survey group by surveyor IList <TLoanSurvey> listSurvey = _tLoanSurveyRepository.GetListBySurveyDate(recPeriod.PeriodFrom, recPeriod.PeriodTo); var recapSurvey = from survey in listSurvey where survey.LoanId.SurveyorId != null group survey by survey.LoanId.SurveyorId into grouped select new { SurveyorId = grouped.Key, CountSurvey = grouped.Count(x => x.LoanId.SurveyorId != null) }; //save survey commission foreach (var recap in recapSurvey) { SaveCommission(recPeriod, EnumCommissionType.IncentiveSurvey, EnumDepartment.SU, recap.SurveyorId, 1, recap.CountSurvey, incentiveSurvey); } //get loan group by surveyor that status is OK var recapLoan = from loan in listLoan where loan.LoanStatus == EnumLoanStatus.OK.ToString() && loan.SurveyorId != null group loan by loan.SurveyorId into grouped select new { SurveyorId = grouped.Key, CountLoan = grouped.Count(x => x.SurveyorId != null) }; //save loan commission foreach (var recap in recapLoan) { SaveCommission(recPeriod, EnumCommissionType.IncentiveApprove, EnumDepartment.SU, recap.SurveyorId, 1, recap.CountLoan, incentiveApprove); } }
private void commissionStatusComboBox_SelectedIndexChanged(object sender, EventArgs e) { MCommission comm = (MCommission)DataMaster.GetObjectByProperty(typeof(MCommission), MCommission.ColumnNames.CommissionStatus, commissionStatusComboBox.SelectedItem.ToString()); if (comm == null) { comm = new MCommission(); } commissionValueNumericUpDown.Value = comm.CommissionValue; commissionDescTextBox.Text = comm.CommissionDesc; FillCommissionShareTabPages(comm.CommissionId, false); }
private void ShareCommission(decimal commission, bool isPacket, string employeeId, string employeeId2, string transactionDesk, decimal transactionId, string transactionFactur) { MCommission comm = null; if (isPacket) { comm = (MCommission)DataMaster.GetObjectByProperty(typeof(MCommission), MCommission.ColumnNames.CommissionStatus, ListOfCommission.Puyer.ToString()); } else { comm = (MCommission)DataMaster.GetObjectByProperty(typeof(MCommission), MCommission.ColumnNames.CommissionStatus, ListOfCommission.Non_Puyer.ToString()); } if (comm != null) { IList listShareComm = DataMaster.GetListEq(typeof(MCommissionShare), MCommissionShare.ColumnNames.CommissionId, comm.CommissionId); MCommissionShare commShare; decimal shareValue; for (int i = 0; i < listShareComm.Count; i++) { commShare = (MCommissionShare)listShareComm[i]; shareValue = commShare.ShareValue / 100 * commission; if (commShare.ShareTo == ListOfCommissionShare.Dokter.ToString() && !string.IsNullOrEmpty(employeeId)) { SaveTCommission(commShare.ShareTo, employeeId, shareValue, transactionId, transactionFactur); } else if (commShare.ShareTo == ListOfCommissionShare.Manager.ToString()) { SaveTCommission(commShare.ShareTo, ListOfCommissionShare.Manager.ToString(), shareValue, transactionId, transactionFactur); } else if (commShare.ShareTo == ListOfCommissionShare.Petugas.ToString() && !string.IsNullOrEmpty(employeeId2)) { SaveTCommission(commShare.ShareTo, employeeId2, shareValue, transactionId, transactionFactur); } else if (commShare.ShareTo == ListOfCommissionShare.Ruang_Apotek.ToString()) { SaveTCommission(commShare.ShareTo, ListOfCommissionShare.Ruang_Apotek.ToString(), shareValue, transactionId, transactionFactur); } else if (commShare.ShareTo == ListOfCommissionShare.Ruangan.ToString() && !string.IsNullOrEmpty(transactionDesk)) { SaveTCommission(commShare.ShareTo, transactionDesk, shareValue, transactionId, transactionFactur); } } } }
/// <summary> /// Process - copy /// </summary> /// <returns>message</returns> protected override String DoIt() { log.Info("doIt - C_Commission_ID=" + _C_Commission_ID + " - copy to " + _C_CommissionTo_ID); MCommission comFrom = new MCommission(GetCtx(), _C_Commission_ID, Get_Trx()); if (comFrom.Get_ID() == 0) { throw new Exception("No From Commission"); } MCommission comTo = new MCommission(GetCtx(), _C_CommissionTo_ID, Get_Trx()); if (comTo.Get_ID() == 0) { throw new Exception("No To Commission"); } // int no = comTo.CopyLinesFrom(comFrom); return("@Copied@: " + no); }
public ActionResult Delete(MCommission viewModel, FormCollection formCollection) { MCommission commission = _mCommissionRepository.Get(viewModel.Id); if (commission != null) { _mCommissionRepository.Delete(commission); } try { _mCommissionRepository.DbContext.CommitChanges(); } catch (Exception e) { _mCommissionRepository.DbContext.RollbackTransaction(); return(Content(e.GetBaseException().Message)); } return(Content("Data Komisi Berhasil Dihapus")); }
public ActionResult Update(MCommission viewModel, FormCollection formCollection) { MCommission commission = _mCommissionRepository.Get(viewModel.Id); TransferFormValuesTo(commission, formCollection); commission.ModifiedDate = DateTime.Now; commission.ModifiedBy = User.Identity.Name; commission.DataStatus = EnumDataStatus.Updated.ToString(); _mCommissionRepository.Update(commission); try { _mCommissionRepository.DbContext.CommitChanges(); } catch (Exception e) { _mCommissionRepository.DbContext.RollbackTransaction(); return(Content(e.GetBaseException().Message)); } return(Content("Data Komisi Berhasil Diupdate")); }
/// <summary> /// Perform Process. /// </summary> /// <returns>Message (variables are parsed)</returns> protected override String DoIt() { log.Info("doIt - C_CommissionRun_ID=" + GetRecord_ID()); // Load Data MCommissionRun comRun = new MCommissionRun(GetCtx(), GetRecord_ID(), Get_Trx()); if (comRun.Get_ID() == 0) { throw new ArgumentException("CommissionAPInvoice - No Commission Run"); } if (Env.ZERO.CompareTo(comRun.GetGrandTotal()) == 0) { throw new ArgumentException("@GrandTotal@ = 0"); } MCommission com = new MCommission(GetCtx(), comRun.GetC_Commission_ID(), Get_Trx()); if (com.Get_ID() == 0) { throw new ArgumentException("CommissionAPInvoice - No Commission"); } if (com.GetC_Charge_ID() == 0) { throw new ArgumentException("CommissionAPInvoice - No Charge on Commission"); } MBPartner bp = new MBPartner(GetCtx(), com.GetC_BPartner_ID(), Get_Trx()); if (bp.Get_ID() == 0) { throw new ArgumentException("CommissionAPInvoice - No BPartner"); } // Create Invoice MInvoice invoice = new MInvoice(GetCtx(), 0, null); invoice.SetClientOrg(com.GetAD_Client_ID(), com.GetAD_Org_ID()); invoice.SetC_DocTypeTarget_ID(MDocBaseType.DOCBASETYPE_APINVOICE); // API invoice.SetBPartner(bp); // invoice.setDocumentNo (comRun.getDocumentNo()); // may cause unique constraint invoice.SetSalesRep_ID(GetAD_User_ID()); // caller // if (com.GetC_Currency_ID() != invoice.GetC_Currency_ID()) { throw new ArgumentException("CommissionAPInvoice - Currency of PO Price List not Commission Currency"); } // if (!invoice.Save()) { throw new Exception("CommissionAPInvoice - cannot save Invoice"); } // Create Invoice Line MInvoiceLine iLine = new MInvoiceLine(invoice); iLine.SetC_Charge_ID(com.GetC_Charge_ID()); iLine.SetQty(1); iLine.SetPrice(comRun.GetGrandTotal()); iLine.SetTax(); if (!iLine.Save()) { throw new Exception("CommissionAPInvoice - cannot save Invoice Line"); } // return("@C_Invoice_ID@ = " + invoice.GetDocumentNo()); }
/// <summary> /// Perform Process /// </summary> /// <returns>Message (text with variables)</returns> protected override String DoIt() { log.Info("C_Commission_ID=" + GetRecord_ID() + ", StartDate=" + p_StartDate); if (p_StartDate == null) { p_StartDate = DateTime.Now; } m_com = new MCommission(GetCtx(), GetRecord_ID(), Get_Trx()); if (m_com.Get_ID() == 0) { throw new Exception("No Commission"); } // Create Commission MCommissionRun comRun = new MCommissionRun(m_com); SetStartEndDate(); comRun.SetStartDate(p_StartDate); System.Threading.Thread.CurrentThread.CurrentCulture = Utility.Env.GetLanguage(GetCtx()).GetCulture(Utility.Env.GetLoginLanguage(GetCtx()).GetAD_Language()); System.Threading.Thread.CurrentThread.CurrentUICulture = Utility.Env.GetLanguage(GetCtx()).GetCulture(Utility.Env.GetLoginLanguage(GetCtx()).GetAD_Language()); // 01-Jan-2000 - 31-Jan-2001 - USD Classes.SimpleDateFormat format = Classes.DisplayType.GetDateFormat(Classes.DisplayType.Date); String description = format.Format(p_StartDate) + " - " + format.Format(m_EndDate) + " - " + MCurrency.GetISO_Code(GetCtx(), m_com.GetC_Currency_ID()); //string description = p_StartDate // + " - " + m_EndDate // + " - " + MCurrency.GetISO_Code(GetCtx(), m_com.GetC_Currency_ID()); comRun.SetDescription(description); System.Threading.Thread.CurrentThread.CurrentCulture = Utility.Env.GetLanguage(GetCtx()).GetCulture(Utility.Env.GetBaseAD_Language()); System.Threading.Thread.CurrentThread.CurrentUICulture = Utility.Env.GetLanguage(GetCtx()).GetCulture(Utility.Env.GetBaseAD_Language()); if (!comRun.Save()) { throw new Exception("Could not save Commission Run please check Organization"); } MCommissionLine[] lines = m_com.GetLines(); for (int i = 0; i < lines.Length; i++) { #region #endregion // Amt for Line - Updated By Trigger MCommissionAmt comAmt = new MCommissionAmt(comRun, lines[i].GetC_CommissionLine_ID()); if (!comAmt.Save()) { throw new SystemException("Could not save Commission Amt"); } // StringBuilder sql = new StringBuilder(); if (MCommission.DOCBASISTYPE_Receipt.Equals(m_com.GetDocBasisType())) { if (m_com.IsListDetails()) { sql.Append("SELECT h.C_Currency_ID, (l.LineNetAmt*al.Amount/h.GrandTotal) AS Amt," + " (l.QtyInvoiced*al.Amount/h.GrandTotal) AS Qty," + " NULL, l.C_InvoiceLine_ID, p.DocumentNo||'_'||h.DocumentNo," + " COALESCE(prd.Value,l.Description), h.DateInvoiced " + "FROM C_Payment p" + " INNER JOIN C_AllocationLine al ON (p.C_Payment_ID=al.C_Payment_ID)" + " INNER JOIN C_Invoice h ON (al.C_Invoice_ID = h.C_Invoice_ID)" + " INNER JOIN C_InvoiceLine l ON (h.C_Invoice_ID = l.C_Invoice_ID) " + " LEFT OUTER JOIN M_Product prd ON (l.M_Product_ID = prd.M_Product_ID) " + "WHERE p.DocStatus IN ('CL','CO','RE')" + " AND h.IsSOTrx='Y'" + " AND p.AD_Client_ID = @clientid" + " AND l.IsCommissionCalculated = 'N' " + " AND p.DateTrx BETWEEN @sdate AND @edate"); } else { sql.Append("SELECT h.C_Currency_ID, SUM(l.LineNetAmt*al.Amount/h.GrandTotal) AS Amt," + " SUM(l.QtyInvoiced*al.Amount/h.GrandTotal) AS Qty," + " NULL, NULL, NULL, NULL, MAX(h.DateInvoiced) " + "FROM C_Payment p" + " INNER JOIN C_AllocationLine al ON (p.C_Payment_ID=al.C_Payment_ID)" + " INNER JOIN C_Invoice h ON (al.C_Invoice_ID = h.C_Invoice_ID)" + " INNER JOIN C_InvoiceLine l ON (h.C_Invoice_ID = l.C_Invoice_ID) " + "WHERE p.DocStatus IN ('CL','CO','RE')" + " AND h.IsSOTrx='Y'" + " AND p.AD_Client_ID = @clientid" + " AND l.IsCommissionCalculated = 'N' " + " AND p.DateTrx BETWEEN @sdate AND @edate"); } } else if (MCommission.DOCBASISTYPE_Order.Equals(m_com.GetDocBasisType())) { if (m_com.IsListDetails()) { sql.Append("SELECT h.C_Currency_ID, l.LineNetAmt, l.QtyOrdered, " + "l.C_OrderLine_ID, NULL, h.DocumentNo," + " COALESCE(prd.Value,l.Description),h.DateOrdered " + "FROM C_Order h" + " INNER JOIN C_OrderLine l ON (h.C_Order_ID = l.C_Order_ID)" + " LEFT OUTER JOIN M_Product prd ON (l.M_Product_ID = prd.M_Product_ID) " + "WHERE h.DocStatus IN ('CL','CO')" + " AND h.IsSOTrx='Y'" + " AND h.AD_Client_ID = @clientid" + " AND l.IsCommissionCalculated = 'N' " + " AND h.DateOrdered BETWEEN @sdate AND @edate"); } else { sql.Append("SELECT h.C_Currency_ID, SUM(l.LineNetAmt) AS Amt," + " SUM(l.QtyOrdered) AS Qty, " + "NULL, NULL, NULL, NULL, MAX(h.DateOrdered) " + "FROM C_Order h" + " INNER JOIN C_OrderLine l ON (h.C_Order_ID = l.C_Order_ID) " + "WHERE h.DocStatus IN ('CL','CO')" + " AND h.IsSOTrx='Y'" + " AND l.IsCommissionCalculated = 'N' " + " AND h.AD_Client_ID = @clientid" + " AND h.DateOrdered BETWEEN @sdate AND @edate"); } } else // Invoice Basis { if (m_com.IsListDetails()) { sql.Append("SELECT h.C_Currency_ID, l.LineNetAmt, l.QtyInvoiced, " + "NULL, l.C_InvoiceLine_ID, h.DocumentNo," + " COALESCE(prd.Value,l.Description),h.DateInvoiced " + "FROM C_Invoice h" + " INNER JOIN C_InvoiceLine l ON (h.C_Invoice_ID = l.C_Invoice_ID)" + " LEFT OUTER JOIN M_Product prd ON (l.M_Product_ID = prd.M_Product_ID) " + "WHERE h.DocStatus IN ('CL','CO','RE')" + " AND h.IsSOTrx='Y'" + " AND l.IsCommissionCalculated = 'N' " + " AND h.AD_Client_ID = @clientid" + " AND h.DateInvoiced BETWEEN @sdate AND @edate"); } else { sql.Append("SELECT h.C_Currency_ID, SUM(l.LineNetAmt) AS Amt," + " SUM(l.QtyInvoiced) AS Qty, " + "NULL, NULL, NULL, NULL, MAX(h.DateInvoiced) " + "FROM C_Invoice h" + " INNER JOIN C_InvoiceLine l ON (h.C_Invoice_ID = l.C_Invoice_ID) " + "WHERE h.DocStatus IN ('CL','CO','RE')" + " AND h.IsSOTrx='Y'" + " AND l.IsCommissionCalculated = 'N' " + " AND h.AD_Client_ID = @clientid" + " AND h.DateInvoiced BETWEEN @sdate AND @edate"); } } // CommissionOrders/Invoices if (lines[i].IsCommissionOrders()) { MUser[] users = MUser.GetOfBPartner(GetCtx(), m_com.GetC_BPartner_ID()); if (users == null || users.Length == 0) { throw new Exception("Commission Business Partner has no Users/Contact"); } if (users.Length == 1) { int SalesRep_ID = users[0].GetAD_User_ID(); sql.Append(" AND h.SalesRep_ID=").Append(SalesRep_ID); } else { log.Warning("Not 1 User/Contact for C_BPartner_ID=" + m_com.GetC_BPartner_ID() + " but " + users.Length); sql.Append(" AND h.SalesRep_ID IN (SELECT AD_User_ID FROM AD_User WHERE C_BPartner_ID=") .Append(m_com.GetC_BPartner_ID()).Append(")"); } } //added by Arpit Rai on 7-May-2016 asked & Tested by Ravikant Sir //To calculate Commission Amount For the Particular Agent If Not Selected in Line Tab Of Commission else { MUser[] users = MUser.GetOfBPartner(GetCtx(), m_com.GetC_BPartner_ID()); if (users == null || users.Length == 0) { throw new Exception("Commission Business Partner has no Users/Contact"); } if (users.Length == 1) { int SaleRepID = users[0].GetAD_User_ID(); sql.Append(" AND h.SalesRep_ID = "); sql.Append(SaleRepID); } else { log.Warning("Not 1 User/Contact for C_BPartner_ID=" + m_com.GetC_BPartner_ID() + " but " + users.Length); sql.Append(" AND h.SalesRep_ID IN (SELECT AD_User_ID FROM AD_User WHERE C_BPartner_ID=") .Append(m_com.GetC_BPartner_ID()).Append(")"); } } // Organization if (lines[i].GetOrg_ID() != 0) { sql.Append(" AND h.AD_Org_ID=").Append(lines[i].GetOrg_ID()); } // BPartner if (lines[i].GetC_BPartner_ID() != 0) { sql.Append(" AND h.C_BPartner_ID=").Append(lines[i].GetC_BPartner_ID()); } // BPartner Group if (lines[i].GetC_BP_Group_ID() != 0) { sql.Append(" AND h.C_BPartner_ID IN " + "(SELECT C_BPartner_ID FROM C_BPartner WHERE C_BP_Group_ID=").Append(lines[i].GetC_BP_Group_ID()).Append(")"); } // Sales Region if (lines[i].GetC_SalesRegion_ID() != 0) { sql.Append(" AND h.C_BPartner_Location_ID IN " + "(SELECT C_BPartner_Location_ID FROM C_BPartner_Location WHERE C_SalesRegion_ID=").Append(lines[i].GetC_SalesRegion_ID()).Append(")"); } // Product if (lines[i].GetM_Product_ID() != 0) { sql.Append(" AND l.M_Product_ID=").Append(lines[i].GetM_Product_ID()); } // Product Category if (lines[i].GetM_Product_Category_ID() != 0) { sql.Append(" AND l.M_Product_ID IN " + "(SELECT M_Product_ID FROM M_Product WHERE M_Product_Category_ID=").Append(lines[i].GetM_Product_Category_ID()).Append(")"); } // Grouping if (!m_com.IsListDetails()) { sql.Append(" GROUP BY h.C_Currency_ID"); } // log.Fine("Line=" + lines[i].GetLine() + " - " + sql); // CreateDetail(sql.ToString(), comAmt); //comAmt.CalculateCommission(); comAmt.CalculatecommissionwithNewLogic(); comAmt.Save(); int countDetails = Util.GetValueOfInt(DataBase.DB.ExecuteScalar("SELECT COUNT(*) FROM C_CommissionDetail WHERE C_CommissionAmt_ID=" + comAmt.GetC_CommissionAmt_ID(), null, Get_TrxName())); if (countDetails == 0) { comAmt.Delete(true, Get_Trx()); } } // for all commission lines // comRun.updateFromAmt(); // comRun.save(); // Save Last Run m_com.SetDateLastRun(p_StartDate); m_com.Save(); return("@C_CommissionRun_ID@ = " + comRun.GetDocumentNo() + " - " + comRun.GetDescription()); }
/// <summary> /// Perform Process. /// </summary> /// <returns>Message (variables are parsed)</returns> protected override String DoIt() { log.Info("doIt - C_CommissionRun_ID=" + GetRecord_ID()); // Load Data MCommissionRun comRun = new MCommissionRun(GetCtx(), GetRecord_ID(), Get_Trx()); if (comRun.Get_ID() == 0) { throw new ArgumentException("CommissionAPInvoice - No Commission Run"); } if (Env.ZERO.CompareTo(comRun.GetGrandTotal()) == 0) { throw new ArgumentException("@GrandTotal@ = 0"); } MCommission com = new MCommission(GetCtx(), comRun.GetC_Commission_ID(), Get_Trx()); if (com.Get_ID() == 0) { throw new ArgumentException("CommissionAPInvoice - No Commission"); } if (com.GetC_Charge_ID() == 0) { throw new ArgumentException("CommissionAPInvoice - No Charge on Commission"); } MBPartner bp = new MBPartner(GetCtx(), com.GetC_BPartner_ID(), Get_Trx()); if (bp.Get_ID() == 0) { throw new ArgumentException("CommissionAPInvoice - No BPartner"); } // Create Invoice MInvoice invoice = new MInvoice(GetCtx(), 0, null); invoice.SetClientOrg(com.GetAD_Client_ID(), com.GetAD_Org_ID()); invoice.SetC_DocTypeTarget_ID(MDocBaseType.DOCBASETYPE_APINVOICE); // API invoice.SetBPartner(bp); // JID_0101: When we generate the AP invoice from Commission run window, its giving price list error. if (invoice.GetM_PriceList_ID() == 0) { string sql = "SELECT M_PriceList_ID FROM M_PriceList WHERE IsActive = 'Y' AND AD_Client_ID = " + com.GetAD_Client_ID() + " AND AD_Org_ID = " + com.GetAD_Org_ID() + " AND IsDefault='Y' AND IsSOPriceList='N'"; int pricelist = Util.GetValueOfInt(DB.ExecuteScalar(sql, null, Get_Trx())); if (pricelist == 0) { pricelist = MPriceList.GetDefault(GetCtx(), false).Get_ID(); } if (pricelist > 0) { invoice.SetM_PriceList_ID(pricelist); } } // invoice.setDocumentNo (comRun.getDocumentNo()); // may cause unique constraint invoice.SetSalesRep_ID(GetAD_User_ID()); // caller // if (com.GetC_Currency_ID() != invoice.GetC_Currency_ID()) { throw new ArgumentException("CommissionAPInvoice - Currency of PO Price List not Commission Currency"); } // if (!invoice.Save()) { //return GetReterivedError(invoice, "CommissionAPInvoice - cannot save Invoice"); throw new Exception("CommissionAPInvoice - cannot save Invoice"); } // Create Invoice Line MInvoiceLine iLine = new MInvoiceLine(invoice); iLine.SetC_Charge_ID(com.GetC_Charge_ID()); iLine.SetQty(1); iLine.SetPrice(comRun.GetGrandTotal()); iLine.SetTax(); if (!iLine.Save()) { //return GetReterivedError(iLine, "CommissionAPInvoice - cannot save Invoice Line"); throw new Exception("CommissionAPInvoice - cannot save Invoice Line"); } // return("@C_Invoice_ID@ = " + invoice.GetDocumentNo()); }
private void CalculateCommissionTLS(TRecPeriod recPeriod, IList <TLoan> listLoan) { MCommission comm = _mCommissionRepository.GetCommissionByDate(EnumDepartment.TLS, recPeriod.PeriodFrom, recPeriod.PeriodTo); if (comm == null) { throw new Exception("Data komisi untuk TLS tidak tersedia."); } //target mapped to commissionvalue //next to do, changes it to target decimal target = comm.CommissionValue.Value; IList <MCommissionDet> listDets = comm.CommissionDets; //get loan group by tls that status is OK var recapLoan = from loan in listLoan where loan.LoanStatus == EnumLoanStatus.OK.ToString() && loan.TLSId != null group loan by loan.TLSId into grouped select new { TLSId = grouped.Key, SumLoan = grouped.Sum(x => x.LoanBasicPrice) }; //save TLS commission MCommissionDet det; foreach (var recap in recapLoan) { decimal percentReal = Math.Ceiling(target != 0 ? recap.SumLoan.Value / target * 100 : 0); decimal percentCalc = percentReal > 100 ? 100 : percentReal; //get total to calculate,if realization more than 100, use target value //if not use sumloan decimal totalToCalc = percentReal > 100 ? target : recap.SumLoan.Value; //get incentive det = (from d in listDets where d.DetailLowTarget <= percentCalc && d.DetailHighTarget >= percentCalc select d).FirstOrDefault(); //check if it has commission to calculate if (det != null) { //normal commission SaveCommission(recPeriod, EnumCommissionType.Commission, EnumDepartment.TLS, recap.TLSId, 1, totalToCalc, det.DetailValue.Value / 100); //if real > 100, sisa calculate new commission if (percentReal > 100) { det = (from d in listDets where d.DetailLowTarget > 100 select d).FirstOrDefault(); //check if it has commission to calculate if (det != null) { //above normal commission SaveCommission(recPeriod, EnumCommissionType.Commission, EnumDepartment.TLS, recap.TLSId, 2, recap.SumLoan.Value - target, det.DetailValue.Value / 100); } } } } }
private void CalculateCommissionSales(TRecPeriod recPeriod, IList <TLoan> listLoan) { MCommission comm = _mCommissionRepository.GetCommissionByDate(EnumDepartment.SA, recPeriod.PeriodFrom, recPeriod.PeriodTo); if (comm == null) { throw new Exception("Data komisi untuk SA tidak tersedia."); } IList <MCommissionDet> listDets = (from det in comm.CommissionDets orderby det.DetailCustomerNumber descending select det).ToList(); //get loan group by SA that status is OK var recapLoan = from loan in listLoan where loan.LoanStatus == EnumLoanStatus.OK.ToString() && loan.SalesmanId != null group loan by loan.SalesmanId into grouped select new { SalesmanId = grouped.Key, SumLoan = grouped.Sum(x => x.LoanBasicPrice), CountLoan = grouped.Count(x => x.SalesmanId != null) }; IList <TLoan> listOrderedLoan = (from loan in listLoan where loan.LoanStatus == EnumLoanStatus.OK.ToString() && loan.SalesmanId != null orderby loan.LoanAccDate select loan).ToList(); TLoan loanToCalc; int startLoanNo = 0; int endLoanNo = 0; decimal commissionRun = 0; int sisaLoan = 0; bool hasInsertAddedIncentive = false; //get commission value foreach (var recap in recapLoan) { //get loan by salesman listOrderedLoan = (from loan in listLoan where loan.LoanStatus == EnumLoanStatus.OK.ToString() && loan.SalesmanId != null && loan.SalesmanId == recap.SalesmanId orderby loan.LoanAccDate select loan).ToList(); sisaLoan = recap.CountLoan; startLoanNo = 0; endLoanNo = 0; hasInsertAddedIncentive = false; //loop commission detail foreach (MCommissionDet det in listDets) { //search commission commissionRun = det.DetailCustomerNumber != 0 ? sisaLoan / det.DetailCustomerNumber : 0; if (commissionRun >= 1) { //get number of last loan to calculate with current commission endLoanNo = endLoanNo + Convert.ToInt32(Math.Ceiling(commissionRun) * det.DetailCustomerNumber); //get sisa loan sisaLoan = sisaLoan - endLoanNo; //loop loan for (int j = startLoanNo; j < endLoanNo; j++) { //save commission loanToCalc = listOrderedLoan[j]; SaveCommission(recPeriod, EnumCommissionType.Commission, EnumDepartment.SA, recap.SalesmanId, j, loanToCalc.LoanBasicPrice, det.DetailValue / 100, loanToCalc.LoanCode); } startLoanNo = endLoanNo; //insert other incentive if (!hasInsertAddedIncentive) { SaveCommission(recPeriod, EnumCommissionType.TransportAllowance, EnumDepartment.SA, recap.SalesmanId, endLoanNo, 30, det.DetailTransportAllowance); SaveCommission(recPeriod, EnumCommissionType.IncentiveCredit, EnumDepartment.SA, recap.SalesmanId, endLoanNo + 1, 1, det.DetailIncentive); hasInsertAddedIncentive = true; } } } } }
private void CalculateCommissionCollector(TRecPeriod recPeriod, IList <TLoan> listLoan) { MCommission comm = _mCommissionRepository.GetCommissionByDate(EnumDepartment.COL, recPeriod.PeriodFrom, recPeriod.PeriodTo); if (comm == null) { throw new Exception("Data komisi untuk kolektor tidak tersedia."); } IList <MCommissionDet> listDets = comm.CommissionDets; IList <MZoneEmployee> zoneEmployees = _mZoneEmployeeRepository.GetListByDate(recPeriod.PeriodFrom, recPeriod.PeriodTo); IList <MZoneEmployee> orderedZe = (from ze in zoneEmployees orderby ze.EmployeeId.Id select ze).ToList(); //get installment group by tls that status is OK IList <TInstallment> listInstallment = _installmentRepository.GetListByMaturityDate(recPeriod.PeriodFrom, recPeriod.PeriodTo); //save collector commission MCommissionDet det; MEmployee tempEmp = null; decimal? target = 0; decimal? real = 0; foreach (MZoneEmployee ze in orderedZe) { //get total by employee //if (tempEmp != null) { if (ze.EmployeeId == tempEmp) { //sum target and real by employee //get target and real target = target + (from ins in listInstallment where ins.LoanId.ZoneId == ze.ZoneId select ins.InstallmentBasic).Sum(); real = real + (from ins in listInstallment where ins.LoanId.ZoneId == ze.ZoneId && ins.InstallmentStatus == EnumInstallmentStatus.Paid.ToString() && ins.InstallmentPaymentDate <= ins.InstallmentMaturityDate select ins.InstallmentBasic).Sum(); } else { //calculate commission if (tempEmp != null) { CalculateCommissionCollectorDetail(recPeriod, target, real, tempEmp, listDets); } target = 0; real = 0; } } tempEmp = ze.EmployeeId; } //calculate last commission if (tempEmp != null) { CalculateCommissionCollectorDetail(recPeriod, target, real, tempEmp, listDets); } }
private static void TransferFormValuesTo(MCommission commission, FormCollection formCollection) { commission.CommissionStartDate = Helper.CommonHelper.ConvertToDate(formCollection["CommissionStartDate"]); commission.CommissionEndDate = Helper.CommonHelper.ConvertToDate(formCollection["CommissionEndDate"]); commission.CommissionValue = Helper.CommonHelper.ConvertToDecimal(formCollection["CommissionValue"]); }