Esempio n. 1
0
        public string ExportCompensation(bool updateAsExported)
        {
            //Export this driver compensation to file
            StringBuilder export = null;

            try {
                //Setup
                export = new StringBuilder();
                PayPeriod payPeriod = FinanceGateway.GetPayPeriod(this.mEndDate);

                //Export driver compensations and admin charges
                foreach (DriverCompDataset.DriverCompTableRow comp in this.mCompensation.DriverCompTable.Rows)
                {
                    if (comp.Select && comp.TotalAmount > 0)
                    {
                        //Export driver compensation
                        export.AppendLine(formatDriverRecord(payPeriod, comp));

                        //Export Admin fees if applicable
                        DriverCompDataset.DriverRouteTableRow[] routes = (DriverCompDataset.DriverRouteTableRow[]) this.mCompensation.DriverRouteTable.Select("AgentNumber=" + this.mAgentNumber + " AND Operator='" + comp.Operator + "'");
                        decimal adminFee = 0.0M;
                        for (int i = 0; i < routes.Length; i++)
                        {
                            adminFee += routes[i].AdminCharge;
                        }
                        if (adminFee != 0)
                        {
                            export.AppendLine(formatAdminRecord(payPeriod, comp, adminFee));
                        }

                        if (updateAsExported)
                        {
                            //Update all routes as exported
                            for (int i = 0; i < routes.Length; i++)
                            {
                                routes[i].Exported    = DateTime.Today;
                                routes[i].LastUpdated = DateTime.Now;
                                routes[i].UserID      = Environment.UserName;
                                FinanceGateway.UpdateDriverRoute(routes[i]);
                            }
                        }
                    }
                }
                //Refresh routes if they were updated (otherwise, don't change export selections)
                if (updateAsExported)
                {
                    ViewCompensation();
                }
            }
            catch (ApplicationException ex) { throw ex; }
            catch (Exception ex) { throw new ApplicationException(ex.Message, ex); }
            return(export.ToString());
        }