示例#1
0
        public string getDays(MainController.Features feature)
        {
            string days = Read(feature.ToString() + " DAYS", feature.ToString());

            if (string.IsNullOrWhiteSpace(days))
            {
                days = "10";
                setDays(feature, days);
            }
            return(days);
        }
示例#2
0
        public string getSubsidiaries(MainController.Features feature)
        {
            string subs = Read(feature.ToString() + " SUBSIDIARIES", feature.ToString());

            if (string.IsNullOrWhiteSpace(subs))
            {
                subs = "";
                setSubsidiaries(feature, subs);
            }
            return(subs);
        }
示例#3
0
        public HashSet <string> getExistingSIDs(string sql, RproDBHandler rproDBHandler, MainController.Features feature)
        {
            HashSet <string> results = new HashSet <string>();

            using (SqlConnection connection = new SqlConnection(getConnectionString()))
            {
                try
                {
                    connection.Open();
                    SqlCommand    cmd    = new SqlCommand(sql, connection);
                    SqlDataReader reader = cmd.ExecuteReader();
                    while (reader.Read())
                    {
                        results.Add(reader["sid"].ToString());
                    }
                }
                catch (Exception e)
                {
                    string title = feature.ToString() + " exception occured.";
                    string body  = "Exception occured when retrieving existing SIDs from B1 database. Unable to perform matching. Run aborted.";
                    rproDBHandler.addLog(MainController.LogType.EXCEPTION, null, null, feature, body, e);
                    new EmailController(settings).sendEmail(title, body, rproDBHandler, feature);
                    throw e;
                }
                finally
                {
                    connection.Close();
                }
            }
            return(results);
        }
示例#4
0
        public void runUpdateVoucherDiscrepancies()
        {
            error         = 0;
            zeroCostError = 0;
            int    vou_disc_days = Int32.Parse(settings.getDays(feature));
            string day_limit     = DateTime.Now.AddDays((vou_disc_days + 1) * -1).Date.ToString(MsSqlDBHandler.DATE_FORMAT);

            string           sql  = "SELECT SUBSTRING(VOU_SID, 4, len(VOU_SID)-4) AS sid FROM Retailpro_Discrepancy WHERE vou_date >= " + day_limit;
            HashSet <string> sids = null;

            try
            {
                sids = msSqlDBHandler.getExistingSIDs(sql, rproDBHandler, feature);
            }
            catch (Exception)
            {
                return;
            }

            string subsidiaryFilter = settings.getSubsidiaries(feature);

            if (!string.IsNullOrWhiteSpace(subsidiaryFilter))
            {
                subsidiaryFilter = " and vou.sbs_no in (" + subsidiaryFilter + ") ";
            }
            Dictionary <String, List <VoucherDiscrepancyItem> > vou_discrepancies = rproDBHandler.getVoucherDiscrepancies(sids, vou_disc_days, subsidiaryFilter);
            Queue <ZeroCostDocument> zeroCostDocuments = filterZeroDocuments(vou_discrepancies);

            msSqlDBHandler.insertVoucherDiscrepancies(vou_discrepancies, rproDBHandler);
            int zeroCostTotal = zeroCostDocuments.Count;

            rproDBHandler.insertZeroCostDocuments(zeroCostDocuments, MainController.Features.VOU_DISCREPANCY);

            string msg = vou_discrepancies.Count + " vouchers with discrepancies fetched and inserted into B1 with " + error + " error(s). ";

            msg += zeroCostTotal + " items with zero cost were inserted with " + zeroCostError + " errors.";

            if (error + zeroCostTotal > 0)
            {
                string subject = "Errors/Zero cost in B1 Interface for " + feature.ToString();
                string body    = msg;
                body += "Please check log for details.";
                new EmailController(settings).sendEmail(subject, body, rproDBHandler, feature);
            }

            rproDBHandler.addLog(MainController.LogType.REPORT, "", "", feature, msg, null);
        }
示例#5
0
        public void runUpdateSFSVoucherReturns()
        {
            error = 0;
            int vou_return_days = Int32.Parse(settings.getDays(feature));

            string           day_limit = DateTime.Now.AddDays((vou_return_days + 1) * -1).Date.ToString(MsSqlDBHandler.DATE_FORMAT);
            string           sql       = "SELECT VOU_SID AS sid FROM Retailpro_Return WHERE vou_date >= " + day_limit;
            HashSet <string> sids      = null;

            try
            {
                sids = msSqlDBHandler.getExistingSIDs(sql, rproDBHandler, feature);
            }
            catch (Exception)
            {
                return;
            }

            string subsidiaryFilter = settings.getSubsidiaries(feature);

            if (!string.IsNullOrWhiteSpace(subsidiaryFilter))
            {
                subsidiaryFilter = " and vou.sbs_no in (" + subsidiaryFilter + ") ";
            }
            Dictionary <String, List <VoucherReturnItem> > vou_items = rproDBHandler.getSFSVoucherReturnItems(sids, vou_return_days, subsidiaryFilter);

            msSqlDBHandler.insertVoucherReturns(vou_items, rproDBHandler);
            string msg = vou_items.Count + " SFS return vouchers fetched and inserted into B1 with " + error + " error(s). ";

            if (error > 0)
            {
                string subject = "Exceptions encountered when processing " + feature.ToString();
                string body    = msg;
                new EmailController(settings).sendEmail(subject, body, rproDBHandler, feature);
            }
            rproDBHandler.addLog(MainController.LogType.REPORT, "", "", feature, msg, null);
        }
示例#6
0
        public void runItemCost()
        {
            error = 0;
            Dictionary <string, double> B1_costs = msSqlDBHandler.getItemCosts(rproDBHandler);
            string modified_date = rproDBHandler.getServerDate(rproDBHandler);

            if (string.IsNullOrWhiteSpace(modified_date))
            {
                return;
            }
            InventoryBO            inventory = new InventoryBO(modified_date);
            Queue <CostDifference> updates   = rproDBHandler.matchItemCost(B1_costs);

            foreach (CostDifference update in updates)
            {
                if (update.B1cost == 0)
                {
                    rproDBHandler.addLog(MainController.LogType.ERROR, update.item_sid, update.alu, feature, "B1 and Rpro cost mismatch - Cost in B1 is 0 when cost in Rpro is " + update.RproCost.ToString("0.0000"), null);
                }
            }
            if (updates.Count == 0)
            {
                rproDBHandler.addLog(MainController.LogType.REPORT, null, null, feature, "No XML file is created because there are no items to update", null);
                return;
            }

            while (updates.Count > 0)
            {
                CostDifference update = updates.Dequeue();
                inventory.AddInventory(update.item_sid, update.B1cost);
            }
            string filepath = createInventoryXMLFilePath();

            try
            {
                inventory.save(filepath);
            }
            catch (Exception e)
            {
                string subject = "Exception occurred when running " + feature.ToString();
                string body    = "Exception occured when trying to create Inventory.xml during Item Cost. Filepath: " + filepath;
                rproDBHandler.addLog(MainController.LogType.EXCEPTION, null, null, feature, body, e);
                new EmailController(settings).sendEmail(subject, body, rproDBHandler, feature);
                return;
            }

            string message = inventory.inventoryCount() + " items are updated in " + filepath;

            rproDBHandler.addLog(MainController.LogType.REPORT, null, null, feature, message, null);

            string command = settings.getItemCostCMDInstruction();
            string ecm     = settings.getECM();

            if (!string.IsNullOrWhiteSpace(command) && !string.IsNullOrWhiteSpace(ecm))
            {
                try
                {
                    ProcessStartInfo cmdsi = new ProcessStartInfo(ecm);
                    cmdsi.Arguments = command;
                    Process cmd = Process.Start(cmdsi);
                    cmd.WaitForExit();
                    Queue <CostDifference> costDifferences = getCostDifferences();
                    if (costDifferences.Count == 0)
                    {
                        rproDBHandler.addLog(MainController.LogType.REPORT, null, null, feature, "0 cost differences after running item cost.", null);
                    }
                    else
                    {
                        rproDBHandler.addLog(MainController.LogType.ERROR, null, null, feature, costDifferences.Count + " cost differences after running item cost.", null);
                    }
                }
                catch (Exception e)
                {
                    string subject = "Exception occurred when running " + feature.ToString();
                    string body    = "Exception occured when processing Inventory.xml using ECM.";

                    rproDBHandler.addLog(MainController.LogType.EXCEPTION, null, null, feature, "Exception occured when processing Inventory.xml using ECM.", e);
                    new EmailController(settings).sendEmail(subject, body, rproDBHandler, feature);
                    return;
                }
            }
        }
示例#7
0
        public void runUpdateSlips()
        {
            error         = 0;
            zeroCostError = 0;
            int              slip_days = Int32.Parse(settings.getDays(feature));
            string           day_limit = DateTime.Now.AddDays((slip_days + 1) * -1).Date.ToString(MsSqlDBHandler.DATE_FORMAT);
            string           sql       = "SELECT SUBSTRING(SLIP_SID, 4, len(SLIP_SID)-3) AS sid FROM RetailPro_SLIP WHERE SLIP_DATE >= " + day_limit;
            HashSet <string> slipSIDs  = null;

            try
            {
                slipSIDs = msSqlDBHandler.getExistingSIDs(sql, rproDBHandler, MainController.Features.SLIP);
            }
            catch (Exception)
            {
                return;
            }
            string subsidiaryFilter = settings.getSubsidiaries(feature);

            if (!string.IsNullOrWhiteSpace(subsidiaryFilter))
            {
                if (subsidiaryFilter == "1")
                {
                    subsidiaryFilter = " and slip.sbs_no = 1 and slip.in_sbs_no = 1 ";
                }
                else
                {
                    subsidiaryFilter = " and slip.sbs_no in (" + subsidiaryFilter + ") ";
                }
            }
            try
            {
                Queue <Slip> slips     = rproDBHandler.getSlips(slipSIDs, slip_days, subsidiaryFilter);
                int          slipCount = slips.Count;
                msSqlDBHandler.insertSlips(slips, rproDBHandler);
                sql  = "select to_char(item.slip_sid) as doc_sid, alu from slip_item_v item inner join invn_sbs_v invn on item.item_sid = invn.item_sid and invn.sbs_no = 1 ";
                sql += "inner join slip_v slip on slip.slip_sid = item.slip_sid where nvl(invn.cost, 0) = 0 and slip.modified_date >= trunc(sysdate)- " + slip_days + subsidiaryFilter + " order by item.slip_sid";
                Queue <ZeroCostDocument> zeroCostDocuments = rproDBHandler.getZeroCostDocument(sql, MainController.Features.SLIP);
                int zeroCostTotal = zeroCostDocuments.Count;
                rproDBHandler.insertZeroCostDocuments(zeroCostDocuments, MainController.Features.SLIP);

                string msg = slipCount + " Slips fetched and inserted into B1 with " + error + " error(s). \n ";
                msg += zeroCostTotal + " items with zero cost were inserted with " + zeroCostError + " errors.  \n";

                if (error + zeroCostTotal > 0)
                {
                    string subject = "Errors/Zero cost in B1 Interface for  " + feature.ToString();
                    string body    = msg;
                    body += "Please check log for details.";
                    new EmailController(settings).sendEmail(subject, body, rproDBHandler, feature);
                }

                rproDBHandler.addLog(MainController.LogType.REPORT, "", "", MainController.Features.SLIP, msg, null);
            }
            catch (Exception e)
            {
                string subject = "Exception occured when sending processing " + feature.ToString();
                string body    = "An unexpected exception occured: " + e.ToString();
                new EmailController(settings).sendEmail(subject, body, rproDBHandler, feature);
            }
        }
示例#8
0
        public void runUpdateAdjustments()
        {
            error         = 0;
            zeroCostError = 0;
            int              adj_days  = Int32.Parse(settings.getDays(feature));
            string           day_limit = DateTime.Now.AddDays((adj_days + 1) * -1).Date.ToString(MsSqlDBHandler.DATE_FORMAT);
            string           sql       = "SELECT SUBSTRING(ADJ_SID, 4, len(ADJ_SID)-3) AS sid FROM RetailPro_ADJUSTMENT WHERE ADJ_DATE >= " + day_limit;
            HashSet <string> adjSIDs   = null;

            try
            {
                adjSIDs = msSqlDBHandler.getExistingSIDs(sql, rproDBHandler, feature);
            }
            catch (Exception e)
            {
                return;
            }

            string subsidiaryFilter = settings.getSubsidiaries(MainController.Features.ADJUSTMENT);

            if (!string.IsNullOrWhiteSpace(subsidiaryFilter))
            {
                subsidiaryFilter = " and adj.sbs_no in (" + subsidiaryFilter + ") ";
            }
            Dictionary <string, List <Adj_div> > adjustments = rproDBHandler.getAdjustments(adjSIDs, adj_days, subsidiaryFilter);

            System.Console.WriteLine("getAdjustments : " + DateTime.Now);

            msSqlDBHandler.insertAdjustments(adjustments, rproDBHandler);
            // msSqlDBHandler.updateSlipsToDB(slips, rproDBHandler);

            /*
             * with adj as (select distinct item.adj_sid, max(case when invn.cost = 0 then 1 else 0 end) as zeroCostFlag,adj.adj_no as adj_no,
             *   to_char(adj.created_date, 'YYYYMMDD') as adj_date, adj.sbs_no as sbs_no, adj.store_no as store_no, adj.adj_reason_name as reason
             *   from adj_item_v item inner join invn_sbs_v invn on item.item_sid = invn.item_sid and invn.sbs_no = 1
             *   inner join adjustment_v adj on item.adj_sid = adj.adj_sid
             *   where adj.adj_type = 0 and adj.status = 0 and adj.held = 0 and adj.isreversed = 0 and adj.created_date >= sysdate - 15
             *   group by item.adj_sid, adj.adj_no, to_char(adj.created_date, 'YYYYMMDD'), adj.sbs_no , adj.store_no, adj.adj_reason_name
             *   having max(case when invn.cost = 0 then 1 else 0 end) = 1)
             *   select item.adj_sid as doc_sid, invn.alu as alu from adj_item item inner join adj adj on adj.adj_sid = item.adj_sid
             *   inner join invn_sbs_v invn on item.item_sid = invn.item_sid and invn.sbs_no = 1 where nvl(invn.cost, 0) = 0
             */

            sql  = "with adj as (select distinct item.adj_sid, max(case when invn.cost = 0 then 1 else 0 end) as zeroCostFlag,adj.adj_no as adj_no, ";
            sql += "to_char(adj.created_date, 'YYYYMMDD') as adj_date, adj.sbs_no as sbs_no, adj.store_no as store_no, adj.adj_reason_name as reason ";
            sql += "from adj_item_v item inner join invn_sbs_v invn on item.item_sid = invn.item_sid and invn.sbs_no = 1 ";
            sql += "inner join adjustment_v adj on item.adj_sid = adj.adj_sid ";
            sql += "where adj.adj_type = 0 and adj.status = 0 and adj.held = 0 and adj.isreversed = 0 and adj.creating_doc_type!=9 and adj.created_date >= trunc(sysdate) - " + adj_days + subsidiaryFilter + " ";
            sql += "group by item.adj_sid, adj.adj_no, to_char(adj.created_date, 'YYYYMMDD'), adj.sbs_no , adj.store_no, adj.adj_reason_name ";
            sql += "having max(case when invn.cost = 0 then 1 else 0 end) = 1) ";
            sql += "select item.adj_sid as doc_sid, invn.alu as alu from adj_item item inner join adj adj on adj.adj_sid = item.adj_sid ";
            sql += "inner join invn_sbs_v invn on item.item_sid = invn.item_sid and invn.sbs_no = 1 where nvl(invn.cost, 0) = 0 ";
            Queue <ZeroCostDocument> zeroCostDocuments = rproDBHandler.getZeroCostDocument(sql, MainController.Features.ADJUSTMENT);
            int zeroCostTotal = zeroCostDocuments.Count;

            rproDBHandler.insertZeroCostDocuments(zeroCostDocuments, MainController.Features.ADJUSTMENT);
            string msg = adjustments.Count + " Adjustments fetched and inserted into B1 with " + error + " error(s). ";

            msg += zeroCostTotal + " items with zero cost were inserted with " + zeroCostError + " errors.";
            rproDBHandler.addLog(MainController.LogType.REPORT, "", "", MainController.Features.ADJUSTMENT, msg, null);

            if (error > 0 || zeroCostTotal > 0)
            {
                string subject = "Errors/Zero cost in B1 Interface for " + feature.ToString();
                string body    = "There are " + error + " errors when processing " + feature.ToString() + " on " + DateTime.Now.ToString() + ". \n";
                body += zeroCostTotal + " items with zero cost were inserted with " + zeroCostError + " errors.\n";
                body += "Please check log for details.";
                new EmailController(settings).sendEmail(subject, body, rproDBHandler, feature);
            }
        }
示例#9
0
 public void setDays(MainController.Features feature, string days)
 {
     Write(feature.ToString() + " DAYS", days, feature.ToString());
 }
示例#10
0
 public void setSubsidiaries(MainController.Features feature, string subsidiaries)
 {
     Write(feature.ToString() + " SUBSIDIARIES", subsidiaries, feature.ToString());
 }