private void GetCurrentBalance()
        {
            Generate frmGenerate = new Generate();
            DateTime dtDate = DateTime.Now;

            foreach (DataRow dtRow in dsCustomersOverLimit.Tables[0].Rows)
            {
                double d = Convert.ToDouble(dtRow["CurrentBalance"].ToString());
                frmGenerate.CalculateCurrentOutstandingBalance(dtRow["CustomerCode"].ToString(), "", "CalculateCustomer", dtDate);
                decimal deCurrentBalanceValue = Convert.ToDecimal(d);
                if (frmGenerate.deGrandTotal > Convert.ToDecimal(dtRow["CreditLimit"].ToString()))
                {
                    int n = dgFlagCustomers.Rows.Add();
                    dgFlagCustomers.Rows[n].Cells["clCustomerCode"].Value = dtRow["CustomerCode"].ToString();
                    dgFlagCustomers.Rows[n].Cells["clCustomerDesc"].Value = dtRow["CustomerDesc"].ToString();
                    dgFlagCustomers.Rows[n].Cells["clPastelBalance"].Value = dtRow["CurrentBalance"].ToString();
                    dgFlagCustomers.Rows[n].Cells["clCreditLimit"].Value = dtRow["CreditLimit"].ToString();
                    dgFlagCustomers.Rows[n].Cells["clTotalBalance"].Value = frmGenerate.deGrandTotal.ToString("N2");
                }
            }
        }
Exemplo n.º 2
0
        private string BuildGlString(string sDebitAccount, string sCreditAccount, string sReference, string sDescription, string sAmount, string sGDC, string sDocumentNumber, string sOpenItemType,bool bReturnItems)
        {
            Solsage_Process_Management_System.Classes.Generate clGenerate = new Solsage_Process_Management_System.Classes.Generate();
            string sPeriod = clGenerate.GetPeriodValue(DateTime.Now);

            if (bReturnItems)
            {
                double dAmount = Convert.ToDouble(sAmount) * -1;
                sAmount = dAmount.ToString();
            }

            string sImport = sPeriod + "|"; //Period
            sImport += DateTime.Now.ToString("dd/MM/yyyy") + "|"; //Date
            sImport += sGDC + "|"; //GDC
            sImport += sDebitAccount + "|"; //Account Number
            sImport += sReference + "|"; //Reference
            sImport += sDescription + "|"; //Description
            sImport += sAmount + "|"; //Amount
            sImport += "00|"; //Tax Type
            sImport += "0|"; //Tax Amount - No tax on deposit
            sImport += sOpenItemType + "|"; //Open Type - You tell Pastel that the transactions are allocations by setting this field to “A”
            sImport += "|"; //Job Code
            sImport += "|"; //Matching Referent
            sImport += "0|"; //Discount Amount
            sImport += "0|"; //Discount Type
            sImport += sCreditAccount + "|"; //Contra Account
            sImport += "1|"; //Exchange Rate
            sImport += "1"; //Bank exchange rate

            return sImport;
        }
Exemplo n.º 3
0
 private void cmdForecast_Click(object sender, EventArgs e)
 {
     Generate frmGenerate = new Generate();
     //frmGenerate.CalculateCurrentOutstandingBalance("", "00002762", "CalculateDocument");
     frmGenerate.CalculateCurrentOutstandingBalance("DUP006", "", "CalculateCustomer",DateTime.Now);
     //lblForecastValue.Text = frmGenerate.deGrandTotal.ToString("N2");
 }
Exemplo n.º 4
0
        private void Main_Load(object sender, EventArgs e)
        {
            //get activecomponents
            string sActiveComponents = "hh";

                sActiveComponents = ConfigurationSettings.AppSettings.Get("ActiveComponents");

                if (sActiveComponents == null)
                {
                    if (MessageBox.Show("Please specify ActiveComponents Parameters in Config file", "ActiveComponents Parameters", MessageBoxButtons.OK, MessageBoxIcon.Error) == DialogResult.OK)
                    {
                        Application.Exit();

                    }
                }
            if (sActiveComponents == "0")
                aActiveComponents = new string[6] { "1", "0", "0", "0", "0", "0" };
            if (sActiveComponents == "1")
                aActiveComponents = new string[6] { "0", "1", "0", "0", "0", "0" };
            if (sActiveComponents == "2")
                aActiveComponents = new string[6] { "0", "0", "1", "0", "0", "0" };
            if (sActiveComponents == "3")
                aActiveComponents = new string[6] { "0", "0", "0", "1", "0", "0" };
            if (sActiveComponents == "4")
                aActiveComponents = new string[6] { "0", "0", "0", "0", "1", "0" };
            if (sActiveComponents == "5")
                aActiveComponents = new string[6] { "0", "0", "0", "0", "0", "1" };
            //aActiveComponents = new string[6] { "0", "0", "0", "0", "0", "1" };
            // 0 = POS
            // 1 = Manufacturing
            // 2 = BUS
            // 3 = Sync
            // 4 = POS - Site Fasilities (Kings Hire)
            // 5 = DSNJHB

            if (Global.sLogedInUserName != "`1")
            {
                foreach (ToolStripMenuItem toolMenuItem in menuStrip1.Items)
                {
                    if (toolMenuItem != fileToolStripMenuItem)
                    {
                        toolMenuItem.Visible = false;

                        foreach (ToolStripDropDownItem toolMenuDropDownItem in toolMenuItem.DropDownItems)
                        {
                            toolMenuDropDownItem.Visible = false;
                            HideMenuItems(toolMenuDropDownItem);

                        }
                    }
                }
            }

            Generate clGenrate = new Generate();
            Global.sCurrFinPeriod = clGenrate.GetPeriodValue(DateTime.Now);
            Global.bUserMaxNewNumber = true;
            Global.sGlobalDefaultRule = "";
            Global.sGlobalDefaultRuleID = "";
            Global.bUseCalculationRules = false;

            helpToolStripMenuItem1.Visible = true;
            updatesToolStripMenuItem.Visible = true;
            aboutToolStripMenuItem.Visible = true;

            if (aActiveComponents[0].ToString() == "1") //POS
            {
                //Documents
                documentsToolStripMenuItem.Visible = true;
                salesOrderToolStripMenuItem.Visible = true;
                invoicesToolStripMenuItem.Visible = true;
                //Customer
                customersToolStripMenuItem.Visible = true;
                addCustomerToolStripMenuItem.Visible = true;
                //Administrator
                AdministratorToolStripMenuItem.Visible = true;
                workshopMovementToolStripMenuItem.Visible = true;
                bulkInvoicingToolStripMenuItem.Visible = true;
                kitItemSetupToolStripMenuItem.Visible = true;
                dailyTurnoverToolStripMenuItem.Visible = true;
                sendMOSReportsToolStripMenuItem.Visible = true;
                overLimitCustomersToolStripMenuItem.Visible = true;
                itemCodeManagerToolStripMenuItem.Visible = true;
                //Reports
                reportsToolStripMenuItem.Visible = true;
                assetsOnSiteToolStripMenuItem.Visible = true;
                salesOrderToolStripMenuItem1.Visible = true;
                openOrderxToolStripMenuItem.Visible = true;
                itemHistoryToolStripMenuItem.Visible = true;

                if (Global.sLogedInUserType == "1") //Administrator
                {
                    //Administrator
                    addUserToolStripMenuItem.Visible = true;
                    addAttachmentsToolStripMenuItem.Visible = true;
                    //Setup
                    setupToolStripMenuItem.Visible = true;
                    companySetupToolStripMenuItem.Visible = true;
                    closedOrderUtilityToolStripMenuItem.Visible = true;
                    emailAndFaxSendingToolStripMenuItem.Visible = true;
                    publicHolidaySetupToolStripMenuItem.Visible = true;

                    //Reports
                    quickReportsToolStripMenuItem.Visible = true;
                    avgTurnoverPerCustomerToolStripMenuItem.Visible = true;
                    itemHistoryToolStripMenuItem.Visible = true;
                }

            }

            if (aActiveComponents[1].ToString() == "1") //Manu JR13 04/07/2011
            {
                //Documents
                documentsToolStripMenuItem.Visible = true;
                supplierDocumentsToolStripMenuItem.Visible = true;
                customerInvoiceToolStripMenuItem1.Visible = true;

                //Manufacturing
                manufacturingToolStripMenuItem.Visible = true;
                tsmInvtAdjustments.Visible = true;
                stockIssueDocumentToolStripMenuItem.Visible = true;
                productionDocumentToolStripMenuItem.Visible = true;
                producedInventoryManagementToolStripMenuItem.Visible = true;

                //Setup
                setupToolStripMenuItem.Visible = true;
                //printUtilityBarcodesToolStripMenuItem.Visible = true;
                //reportsToolStripMenuItem.Visible = true;
                //manufacturingToolStripMenuItem1.Visible = true;
                //rawItemStockLevelToolStripMenuItem.Visible = true;

                //Reports
                reportsToolStripMenuItem.Visible = true;
                manufacturingToolStripMenuItem1.Visible = true;
                productionSummaryToolStripMenuItem.Visible = true;

                invoicesToolStripMenuItem1.Visible = false;
                assetCostingToolStripMenuItem.Visible = false;
                assetLocationToolStripMenuItem.Visible = false;
                assetsOnSiteToolStripMenuItem.Visible = false;
                salesOrderToolStripMenuItem.Visible = false;
                rawItemStockLevelToolStripMenuItem.Visible = false;
                invoicesToolStripMenuItem.Visible = false;
                liquidAccessComparisonToolStripMenuItem.Visible = false;

                //itemHistoryToolStripMenuItem.Visible = true;

                quickReportsToolStripMenuItem.Visible = false;
                invoicesToolStripMenuItem1.Visible = false;
                liquidAccessComparisonToolStripMenuItem.Visible = false;
                itemHistoryToolStripMenuItem.Visible = false;
                dailyTurnoverToolStripMenuItem.Visible = false;

                if (Global.sLogedInUserType == "1") //Administrator
                {
                    //Manufacturing

                    //Batch Setup

                    //Administrator
                    AdministratorToolStripMenuItem.Visible = true;
                    addUserToolStripMenuItem.Visible = true;
                    addAttachmentsToolStripMenuItem.Visible = true;

                    //Setup
                    companySetupToolStripMenuItem.Visible = true;
                }

            }

            if (aActiveComponents[2].ToString() == "1") //BUS
            {
                //Documents
                documentsToolStripMenuItem.Visible = true;
                supplierDocumentsToolStripMenuItem.Visible = true;
                //Maintenance
                maintenanceToolStripMenuItem.Visible = true;
                addEditAssetToolStripMenuItem.Visible = true;
                issueInventoryForAssetsToolStripMenuItem.Visible = true;
                returnAssetFromAssetToolStripMenuItem.Visible = true;
                //Reports
                reportsToolStripMenuItem.Visible = true;
                assetLocationToolStripMenuItem.Visible = true;
                itemHistoryToolStripMenuItem.Visible = true;

                if (Global.sLogedInUserType == "1") //Administrator
                {
                    //Administrator
                    AdministratorToolStripMenuItem.Visible = true;
                    addUserToolStripMenuItem.Visible = true;
                    //Setup
                    setupToolStripMenuItem.Visible = true;
                    companySetupToolStripMenuItem.Visible = true;
                    //Reports
                    assetCostingToolStripMenuItem.Visible = true;
                    itemHistoryToolStripMenuItem.Visible = true;
                }
            }

            if (aActiveComponents[3].ToString() == "1") //Sync
            {
                //Transfer
                documentTransferToolStripMenuItem.Visible = true;
                documentTransferToolStripMenuItem1.Visible = true;
                errorManagementToolStripMenuItem.Visible = true;

                if (Global.sLogedInUserType == "1") //Administrator
                {
                    //Administrator
                    AdministratorToolStripMenuItem.Visible = true;
                    addUserToolStripMenuItem.Visible = true;
                    //Setup
                    setupToolStripMenuItem.Visible = true;
                    companySetupToolStripMenuItem.Visible = true;
                    tranferSetupToolStripMenuItem.Visible = true;
                    testToolStripMenuItem.Visible = true; //GLCodeSyncSetup
                    inventorySyncSetupToolStripMenuItem.Visible = true;
                    //Sync
                    syncToolStripMenuItem.Visible = true;
                    gLCodeSyncToolStripMenuItem.Visible = true;
                    inventoryItemsToolStripMenuItem.Visible = true;
                }
            }

            if (aActiveComponents[4].ToString() == "1") //POS - Site Fasilities
            {
                //Documents
                documentsToolStripMenuItem.Visible = true;
                salesOrderToolStripMenuItem.Visible = true;
                invoicesToolStripMenuItem.Visible = true;
                //Customer
                customersToolStripMenuItem.Visible = true;
                addCustomerToolStripMenuItem.Visible = true;
                //Administrator
                AdministratorToolStripMenuItem.Visible = true;
                workshopMovementToolStripMenuItem.Visible = true;
                bulkInvoicingToolStripMenuItem.Visible = true;
                addAttachmentsToolStripMenuItem.Visible = true;
                //Reports
                reportsToolStripMenuItem.Visible = true;
                assetsOnSiteToolStripMenuItem.Visible = true;
                salesOrderToolStripMenuItem1.Visible = true;
                openOrderxToolStripMenuItem.Visible = true;
                emailAndFaxSendingToolStripMenuItem.Visible = true;
                publicHolidaySetupToolStripMenuItem.Visible = true;
                liquidAccessComparisonToolStripMenuItem.Visible = true;
                itemHistoryToolStripMenuItem.Visible = true;
                journalToolStripMenuItem.Visible = true;
                supplierJournalToolStripMenuItem.Visible = true;

                //qoutesToolStripMenuItem.Visible = true;
                projectManagementToolStripMenuItem.Visible = true;

                if (Global.sLogedInUserType == "1") //Administrator
                {
                    //Administrator
                    addUserToolStripMenuItem.Visible = true;
                    addAttachmentsToolStripMenuItem.Visible = true;
                    //Setup
                    setupToolStripMenuItem.Visible = true;
                    companySetupToolStripMenuItem.Visible = true;
                    closedOrderUtilityToolStripMenuItem.Visible = true;
                    ruleSetupToolStripMenuItem.Visible = true;
                    //Reports
                    quickReportsToolStripMenuItem.Visible = true;
                    avgTurnoverPerCustomerToolStripMenuItem.Visible = true;
                    liquidMassConverterToolStripMenuItem.Visible = true;
                    liquidAccessComparisonToolStripMenuItem.Visible = true;
                    itemHistoryToolStripMenuItem.Visible = true;
                    setupToolStripMenuItem2.Visible = true;
                    accountDetailsToolStripMenuItem.Visible = true;
                    estimatedTrunoverToolStripMenuItem.Visible = true;
                    marketingToolStripMenuItem.Visible = true;

                }

                Global.bUseCalculationRules = true;
            }

            if (aActiveComponents[5].ToString() == "1") //DSN JHB
            {
                qoutesToolStripMenuItem.Visible = true;

                documentsToolStripMenuItem.Visible = true;
                AdministratorToolStripMenuItem.Visible = true;
                setupToolStripMenuItem.Visible = true;
                companySetupToolStripMenuItem.Visible = true;
                deliveryNoteToolStripMenuItem.Visible = true;
                returnNoteToolStripMenuItem.Visible = true;
                pickingSlipsToolStripMenuItem.Visible = true;
                projectManagementToolStripMenuItem1.Visible = true;
                if (Global.sLogedInUserType == "1") //Administrator
                {
                    //Administrator
                    AdministratorToolStripMenuItem.Visible = true;
                    addUserToolStripMenuItem.Visible = true;
                    //Setup
                    setupToolStripMenuItem.Visible = true;
                    companySetupToolStripMenuItem.Visible = true;
                    projectManagementToolStripMenuItem2.Visible = true;
                }
            }
            //invoicesToolStripMenuItem1.Visible = true;

            Solsage_Pastel_API.solPastelSDK clsSDK = new Solsage_Pastel_API.solPastelSDK();
            string sRet =	clsSDK.invokeSDK(Global.sDataPath);//Initialise the sdk
            if (sRet != "0")
            {
            MessageBox.Show("Error Retrieving Data Files \r\n\r\n" + sRet, "Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            Application.Restart();
            }

            using (PsqlConnection oConn = new PsqlConnection(Solsage_Process_Management_System.Classes.Connect.sConnStr))
            {
                oConn.Open();
                string sSql = "Select * from SOLCS";

                PsqlDataReader rdReader = Solsage_Process_Management_System.Classes.Connect.getDataCommand(sSql, oConn).ExecuteReader();
                while (rdReader.Read())
                {
                    Global.sCompanyName = rdReader["GroupName"].ToString().Trim();
                    Global.sRegName = rdReader["CompanyName"].ToString().Trim();
                    Global.sVAT = rdReader["VATNumber"].ToString().Trim();
                    Global.sReg = rdReader["RegistrationNum"].ToString().Trim();
                    Global.sCompanyTel = rdReader["TelephoneNumber"].ToString().Trim();
                    Global.sCompanyFax = rdReader["FaxNumber"].ToString().Trim();
                    Global.sCompanyAd1 = rdReader["Physical1"].ToString().Trim();
                    Global.sCompanyAd2 = rdReader["Physical2"].ToString().Trim();
                    Global.sCompanyAd3 = rdReader["Physical3"].ToString().Trim();
                    Global.sCompanyPostAd1 = rdReader["Postal1"].ToString().Trim();
                    Global.sCompanyPostAd2 = rdReader["Postal2"].ToString().Trim();
                    Global.sCompanyPostAd3 = rdReader["PostalZip"].ToString().Trim();
                    Global.sDeliveryNoteCompany = rdReader["DeliveryNoteCompany"].ToString();
                    Global.sInvoiceContactName = rdReader["InvoiceContactName"].ToString();
                    Global.sInvoiceContactNumber = rdReader["InvoiceContactNumber"].ToString();
                    Global.sDefaultStore = rdReader["StoreDefault"].ToString().Trim();
                    Global.sQuotePath = rdReader["QuotePath"].ToString().Trim();
                    try
                    {
                        Global.sSalesOrderType = rdReader["SalesOrderType"].ToString().Trim();
                        if (Global.sSalesOrderType == "Long Term AND Short Term")
                            Global.bUseCalculationRules = true;
                    }
                    catch
                    {
                        Global.sSalesOrderType = "";
                    }
                    try
                    {
                        Global.sTermsAndConditions = rdReader["DeliveryNoteTerms"].ToString().Trim();
                    }
                    catch
                    {
                        Global.sTermsAndConditions = "";
                    }

                    try
                    {
                        if (ConfigurationSettings.AppSettings.Get("UseQuantityMeasure") == "1")
                            Global.bUseQuantityMeasure = true;
                    }
                    catch
                    {
                        Global.bUseQuantityMeasure = false;
                    }

                    try
                    {
                        Global.sDefaultSlipPrinter = ConfigurationSettings.AppSettings.Get("SlipPrinter");
                    }
                    catch
                    {
                        Global.sDefaultSlipPrinter = rdReader["DefaultSlipPrinter"].ToString().Trim();
                    }
                    try
                    {
                        Global.sDefaultDocPrinter = ConfigurationSettings.AppSettings.Get("DocumentPrinter");
                    }
                    catch
                    {
                        Global.sDefaultDocPrinter = rdReader["DefaultDocPrinter"].ToString().Trim();
                    }
                    try
                    {
                        Global.sDeliveryNoteFirstPrintCopies = ConfigurationSettings.AppSettings.Get("DeliveryNoteFirstPrintCopies");
                    }
                    catch
                    {
                        Global.sDeliveryNoteFirstPrintCopies = rdReader["DellNoteFirst"].ToString().Trim();
                    }
                    try
                    {
                        Global.sDeliveryNoteDuplicatePrintCopies = ConfigurationSettings.AppSettings.Get("DeliveryNoteDuplicatePrintCopies");
                    }
                    catch
                    {
                        Global.sDeliveryNoteDuplicatePrintCopies = rdReader["DellNoteDuplicate"].ToString().Trim();
                    }
                    try
                    {
                        Global.sInvoiceFirstPrintCopies = ConfigurationSettings.AppSettings.Get("InvoiceFirstPrintCopies");
                    }
                    catch
                    {
                        Global.sInvoiceFirstPrintCopies = rdReader["InvoiceFirst"].ToString().Trim();
                    }
                    try
                    {
                        Global.sInvoiceDuplicatePrintCopies = ConfigurationSettings.AppSettings.Get("InvoiceDuplicatePrintCopies");
                    }
                    catch
                    {
                        Global.sInvoiceDuplicatePrintCopies = rdReader["InvoiceDuplicate"].ToString().Trim();
                    }

                    try
                    {
                        Global.sEmailAddressFrom1 = ConfigurationSettings.AppSettings.Get("MailAddressFrom1");
                    }
                    catch
                    {
                        Global.sEmailAddressFrom1 = "*****@*****.**";
                    }
                    try
                    {
                        Global.sEmailAddressFrom2 = ConfigurationSettings.AppSettings.Get("MailAddressFrom2");
                    }
                    catch
                    {
                        Global.sEmailAddressFrom2 = "*****@*****.**";
                    }
                    try
                    {
                        Global.sEmailAddressFrom3 = ConfigurationSettings.AppSettings.Get("MailAddressFrom3");
                    }
                    catch
                    {
                        Global.sEmailAddressFrom3 = "*****@*****.**";
                    }
                    try
                    {
                        Global.sEmailPasswordFrom1 = ConfigurationSettings.AppSettings.Get("MailPasswordFrom1");
                    }
                    catch
                    {
                        Global.sEmailPasswordFrom1 = "";
                    }
                    try
                    {
                        Global.sEmailPasswordFrom2 = ConfigurationSettings.AppSettings.Get("MailPasswordFrom2");
                    }
                    catch
                    {
                        Global.sEmailPasswordFrom2 = "";
                    }
                    try
                    {
                        Global.sEmailPasswordFrom3 = ConfigurationSettings.AppSettings.Get("MailPasswordFrom3");
                    }
                    catch
                    {
                        Global.sEmailPasswordFrom3 = "";
                    }
                    try
                    {
                        Global.sSmtpClient = ConfigurationSettings.AppSettings.Get("SmtpClient");
                    }
                    catch
                    {
                        Global.sSmtpClient = "smtp.axxess.co.za";
                    }

                    try
                    {
                        Global.sSmtpClientPort = ConfigurationSettings.AppSettings.Get("SmtpClientPort");
                    }
                    catch
                    {
                        Global.sSmtpClientPort = "25";
                    }
                    try
                    {
                        Global.sEmailBody = ConfigurationSettings.AppSettings.Get("MailBody");
                    }
                    catch
                    {
                        Global.sEmailBody = "";
                    }
                    try
                    {
                        if (ConfigurationSettings.AppSettings.Get("Manufacturing") == "1")
                        {
                            Global.bManufacturing = true;
                        }
                        else
                        {
                            Global.bManufacturing = false;
                        }
                    }
                      catch
                    {
                        Global.bManufacturing = false;
                    }
                    try
                    {
                        if (ConfigurationSettings.AppSettings.Get("LogCreateDocument") == "1")
                        {
                            Global.bLogCreateDocument = true;
                        }
                        else
                        {
                            Global.bLogCreateDocument = false;
                        }
                    }
                    catch
                    {
                        Global.bLogCreateDocument = false;
                    }
                    Global.sDeliveryNoteTemplate = rdReader["DeliveryNoteTemplate"].ToString().Trim();
                    Global.sInvoiceTemplate = rdReader["InvoiceTemplate"].ToString().Trim();
                    Global.sQuoteTemplate = rdReader["QuoteTemplate"].ToString().Trim();
                    if( rdReader["DefaultSDKUser"].ToString().Trim() != "")
                    {
                        Global.iPastelSdkUser = Convert.ToInt32(rdReader["DefaultSDKUser"].ToString().Trim());
                    }
                    else
                    {
                         Global.iPastelSdkUser =0;
                    }
                    if (rdReader["AutoInvoiceOnReturn"].ToString() == "1")
                    {
                        Global.bAutoInvoiceOnReturn = true;
                    }
                    else
                    {
                        Global.bAutoInvoiceOnReturn = false;
                    }

                    if (aActiveComponents[4].ToString() == "1") //POS - Site Fasilities
                    {
                        Global.sGlobalDefaultRule = rdReader["sDefaultRuleName"].ToString().Trim();
                        Global.sGlobalDefaultRuleID = rdReader["iDefaultRuleId"].ToString().Trim();
                    }
                    else
                    {
                        Global.sGlobalDefaultRule = "";
                        Global.sGlobalDefaultRuleID = "";
                    }

                    if (rdReader["GenerateZeroInv"].ToString() == "True")
                    {
                        Global.bGenerateZeroInvoice = true;
                    }
                    else
                    {
                        Global.bGenerateZeroInvoice = false;
                    }

                    if (rdReader["AutoBlockCust"].ToString() == "True")
                    {
                        Global.bAutoBlockCustomer = true;
                    }
                    else
                    {
                        Global.bAutoBlockCustomer = false;
                    }

                    //JR 13 6/9/2011
                    if (rdReader["LiquidHandlesInvt"].ToString() == "True")
                        Global.bLiquidHandlesInvt = true;
                    else
                        Global.bLiquidHandlesInvt = false;

                    //********
                }
                //get returnitem status of user
                //check to see whether logged in user is allowed to return item?
                try
                {
                    string sSqlRI = "Select ReturnItem from SOLUS where Code = '" + Global.sLogedInUserCode + "'";
                    Global.iReturnItem = Convert.ToInt16(Connect.getDataCommand(sSqlRI, oConn).ExecuteScalar().ToString());
                    oConn.Dispose();
                }
                catch
                {
                    Global.iReturnItem = 0;
                    oConn.Dispose();
                }

                rdReader.Close();
                oConn.Dispose();
            }
            if (Global.bUseBackground)
            {
                this.BackgroundImage = global::Solsage_Process_Management_System.Properties.Resources._09;
                this.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
            }
               this.Text = "Liquid [" + Global.sActiveCompanyName + "]";
        }
Exemplo n.º 5
0
        private void GetCustomerBalance()
        {
            Generate frmGenerate = new Generate();
            //get end of month date
            DateTime dtDate = new DateTime(DateTime.Now.Year,DateTime.Now.Month,1);
            dtDate = dtDate.AddMonths(1).AddDays(-1);
            decimal dOpenSalesOrderAmount = 0;
            decimal dTotalInvoiceAmount = 0;
            decimal dInvoiceAmount = 0;

            foreach (DataRow dtRow in dsEstimatedTurnover.Tables[0].Rows)
            {
                decimal dTotalBalance = 0;
                frmGenerate.CalculateCurrentOutstandingBalance(dtRow["CustomerCode"].ToString().Trim(), "", "CalculateCustomer", dtDate);
                dOpenSalesOrderAmount = dOpenSalesOrderAmount + frmGenerate.deGrandTotal;
                //dInvoiceAmount = CalculateInvoiceBalance(dtRow["CustomerCode"].ToString().Trim());
                //dTotalInvoiceAmount = dTotalInvoiceAmount + dInvoiceAmount;
                dTotalBalance = frmGenerate.deGrandTotal + dInvoiceAmount;
                dtRow["Balance"] = dTotalBalance.ToString("N2");
                StepProgressBar();
            }
            dTotalInvoiceAmount = CalculateInvoiceBalance();
            //txtOpenSalesOrderValue.Text = dOpenSalesOrderAmount.ToString("N2");
            //txtTotalInvoiceValue.Text = dTotalInvoiceAmount.ToString("N2");
            //txtTotalTurnover.Text = (dTotalInvoiceAmount + dOpenSalesOrderAmount).ToString("N2");
            GenerateReport(dOpenSalesOrderAmount, dTotalInvoiceAmount);
            CompleteProcess();
        }
Exemplo n.º 6
0
        private void DoForecast(DateTime dtForecastUpto)
        {
            if (txtCustomerCode.Text != "")
            {
                Cursor = System.Windows.Forms.Cursors.WaitCursor;

                Generate frmGenerate = new Generate();

                decimal deCurrentBalanceValue = Convert.ToDecimal(lblCurrentBalanceValue.Text.Replace("R", ""));
                frmGenerate.CalculateCurrentOutstandingBalance(txtCustomerCode.Text.Trim(), "", "CalculateCustomer", dtForecastUpto);
                lblForecast.Text = "R" + (frmGenerate.deGrandTotal + deCurrentBalanceValue).ToString("N2");
                lblInfoForecastBalance.Text = "R" + (frmGenerate.deGrandTotal + deCurrentBalanceValue).ToString("N2");
                lblInfoForecast.Text = "R" + frmGenerate.deGrandTotal.ToString("N2");

                Cursor = System.Windows.Forms.Cursors.Default;
                //Block Customer Message on forecast
                //if (Convert.ToDecimal(lblCreditLimitValue.Text.Replace("R", "")) < (frmGenerate.deGrandTotal + deCurrentBalanceValue))
                //{
                //    if (MessageBox.Show("On forecast, customer " + txtCustomerCode.Text.Trim() + " is over his credit limit. Do you want to block this customer?", "Customer Over Credit Limit on Forecast", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                //    {
                //        blockCustomer(txtCustomerCode.Text.Trim());
                //    }

                //}
            }
        }
Exemplo n.º 7
0
        private void cmdInvoice_Click(object sender, EventArgs e)
        {
            string sSiteName = selAddresses.Text.Trim();
            string[] aInvoiceLines= new string[0];
            ArrayList alLinesdata = new ArrayList();
            if (bMonthEndMode)
            {
                if (MessageBox.Show("Are you sure you want to create a tax invoice?", "Create An Invoice?", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    for (int iLines = 0; iLines < aSaleslines.Length; iLines++)
                    {
                        SalesLine slThisLine = (SalesLine)aSaleslines[iLines];
                        if (slThisLine.picReturned.Visible)//Returned Item
                        {
                            if (chkInvoiceReturned.Checked)
                            {
                                Array.Resize<string>(ref aInvoiceLines, aInvoiceLines.Length + 1);	//add this Sales Order Line for deletion
                                aInvoiceLines[aInvoiceLines.Length - 1] = CreateDocLineFromSalesline(slThisLine, iLines + 1); //Add line detail necessary for deletion in the invoice Engine
                            }
                        }
                        else if(slThisLine.chkReturn.Checked || slThisLine.txtCode.Text.StartsWith("*D"))
                        {
                            Array.Resize<string>(ref aInvoiceLines, aInvoiceLines.Length + 1);	//add this Sales Order Line for deletion
                            aInvoiceLines[aInvoiceLines.Length - 1] = CreateDocLineFromSalesline(slThisLine, iLines + 1); //Add line detail necessary for deletion in the invoice Engine
                        }

                    }
                    if (aInvoiceLines.Length > 0)
                    {

                        using (PsqlConnection oConn = new PsqlConnection(Solsage_Process_Management_System.Classes.Connect.sPastelConnStr))
                        {
                            txtSalesCode.Text = Global.sLogedInUserCode;
                            Generate clsGenerate = new Generate();
                            string[] aReturn = clsGenerate.CreateCustomerDocument(txtNumber.Text, 3, aInvoiceLines, txtCustomerCode.Text, txtSalesCode.Text, txtOrderNumber.Text, "MonthEnd", dtInvoiceDate, oConn,"",alLinesdata, sSiteName);
                            if (aReturn[0] == "0")
                            {
                                Cursor = System.Windows.Forms.Cursors.WaitCursor;
                                try
                                {
                                    if (Global.sInvoiceTemplate == "Kings Hire")
                                    {
                                        if (printDialog1.ShowDialog() == DialogResult.OK)
                                        {

                                            Solsage_Process_Management_System.Classes.Functions.printInvoice(aReturn[1], true, false, Global.sLogedInUserCode,printDialog1);
                                        }
                                    }
                                    else
                                    {
                                        PrintDialog pdPrint = new PrintDialog();
                                        Solsage_Process_Management_System.Classes.Functions.printInvoice(aReturn[1], true, false, Global.sLogedInUserCode, pdPrint);
                                    }
                                 }
                                catch
                                {
                                    this.Close();
                                    MessageBox.Show("This Invoice WAS SUCCESSFULLY CREATED. There was an error printing the Invoice. Please reprint invoice at the Invoice Screen. Do not Invoice this sales order again.","Error Printing Invoice",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
                                }
                                Cursor = System.Windows.Forms.Cursors.Default;
                            }
                            else
                            {
                                MessageBox.Show("Error: " + aReturn[1] + "\r\n\r\n Error Number: " + aReturn[0], "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                return;
                            }
                        }
                    }
                    else
                    {
                        MessageBox.Show("No lines to invoice", "No Invoice Lines", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    this.Close();
                }

            }
            else if (bInvoiceMode)
            {

                if (MessageBox.Show("Are you sure you want to create a tax invoice?", "Create An Invoice?", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    //HEADER
                    string sHeader = "";

                    sHeader = "|";  //Document
                    sHeader += "N|"; //Deleted
                    sHeader += "N|"; //Print Status
                    sHeader += txtCustomerCode.Text.Trim() + "|"; //Customer Code 7 chars max
                    sHeader += dtDate.Value.ToString("dd/MM/yyyy") + "|"; //Date

                    sHeader += txtOrderNumber.Text.Trim() + "|"; //Order Number
                    if (txtIncExc.Text == "1")
                        sHeader += "Y|"; //Inclusive / Exclusive
                    else
                        sHeader += "N|"; //Inclusive / Exclusive

                    sHeader += txtDiscount.Text.Trim() + "|"; //Discount
                    //?????
                    sHeader += "" + "|"; //Invoice Messages 3 Fields ????
                    sHeader += "" + "|"; //Invoice Messages 3 Fields ????
                    sHeader += "" + "|"; //Invoice Messages 3 Fields ????

                    sHeader += txtDelAd1.Text.Trim() + "|"; //Delivery Address 1
                    sHeader += txtDelAd2.Text.Trim() + "|"; //Delivery Address 2
                    sHeader += txtDelAd3.Text.Trim() + "|"; //Delivery Address 3
                    sHeader += txtDelAd4.Text.Trim() + "|"; //Delivery Address 4
                    sHeader += txtDelAd5.Text.Trim() + "|"; //Delivery Address 5
                    sHeader += txtSalesCode.Text.Trim() + "|"; //Sales Analysis Code

                    sHeader += lblPaymentTermsValue.Text + "|"; //Settlement Terms Code
                    sHeader += "|"; //Job Code
                    sHeader += dtDate.Text.Trim() + "|"; //Closing Date

                    sHeader += txtTelephone.Text.Trim() + "|"; //Telephone
                    sHeader += txtContact.Text.Trim() + "|"; //Contact
                    sHeader += txtFax.Text.Trim() + "|"; //Fax
                    sHeader += "1.0" + "|"; //Exchange Rate
                    sHeader += "|"; //Discription
                    sHeader += "|"; //ExemptRef

                    sHeader += txtPosAd1.Text.Trim() + "|"; //Post Address 1
                    sHeader += txtPosAd2.Text.Trim() + "|"; //Post Address 2
                    sHeader += txtPosAd3.Text.Trim() + "|"; //Post Address 3
                    sHeader += txtPosAd4.Text.Trim() + "|"; //Post Address 4
                    sHeader += "" + "|"; //Post Address 5

                    sHeader += "" + "|"; //Ship / Deliver
                    sHeader += "adhoc" + "|"; //Freight
                    sHeader += "N"; //On Hold

                    for (int iLines = 0; iLines < aSaleslines.Length; iLines++)
                    {
                        SalesLine slThisLine = (SalesLine)aSaleslines[iLines];
                        //getnewlinedata
                        string[] aGetnewlinedata = new string[8];
                        aGetnewlinedata[0] = dtDeliveryDate.Text;
                        aGetnewlinedata[1] = slThisLine.dtReturnDate.ToString();
                        aGetnewlinedata[2] = slThisLine.dtDelivery.ToString();
                        aGetnewlinedata[3] = "0";
                        aGetnewlinedata[4] = (Convert.ToInt16(slThisLine.iLineIndex) + 1).ToString();
                        aGetnewlinedata[5] = slThisLine.txtMultiplier.Text;
                        aGetnewlinedata[6] = slThisLine.txtQuantity.Text;
                        aGetnewlinedata[7] = "";

                        alLinesdata.Add(aGetnewlinedata);

                        if (slThisLine.picReturned.Visible)//Returned Item
                        {
                            if (chkInvoiceReturned.Checked)
                            {
                                Array.Resize<string>(ref aInvoiceLines, aInvoiceLines.Length + 1);	//add this Sales Order Line for deletion
                                aInvoiceLines[aInvoiceLines.Length - 1] = CreateDocLineFromSalesline(slThisLine, iLines + 1); //Add line detail necessary for deletion in the invoice Engine
                            }
                        }
                        else if (slThisLine.chkReturn.Checked || slThisLine.txtCode.Text == "'")
                        {
                            Array.Resize<string>(ref aInvoiceLines, aInvoiceLines.Length + 1);	//add this Sales Order Line for deletion
                            aInvoiceLines[aInvoiceLines.Length - 1] = CreateDocLineFromSalesline(slThisLine,iLines + 1); //Add line detail necessary for deletion in the invoice Engine
                        }

                    }
                    if (aInvoiceLines.Length > 0)
                    {

                        using (PsqlConnection oConn = new PsqlConnection(Solsage_Process_Management_System.Classes.Connect.sPastelConnStr))
                        {
                            Generate clsGenerate = new Generate();

                            string[] aReturn = clsGenerate.CreateCustomerDocument(txtNumber.Text, 3, aInvoiceLines, txtCustomerCode.Text, txtSalesCode.Text, txtOrderNumber.Text, "Invoice", dtInvoiceDate, oConn, sHeader, alLinesdata, sSiteName);
                            if (aReturn[0] == "0")
                            {
                                Cursor = System.Windows.Forms.Cursors.WaitCursor;
                                try
                                {
                                    if (Global.sInvoiceTemplate == "Kings Hire")
                                    {
                                        if (printDialog1.ShowDialog() == DialogResult.OK)
                                        {
                                            Solsage_Process_Management_System.Classes.Functions.printInvoice(aReturn[1], true, false, Global.sLogedInUserCode, printDialog1);
                                        }
                                    }
                                    else
                                    {
                                        PrintDialog pdPrint = new PrintDialog();
                                        Solsage_Process_Management_System.Classes.Functions.printInvoice(aReturn[1], true, false, Global.sLogedInUserCode, pdPrint);
                                    }
                                    //Solsage_Process_Management_System.Classes.Functions.printInvoice(aReturn[1], true, false, Global.sLogedInUserCode);
                                }
                                catch
                                {
                                    this.Close();
                                    MessageBox.Show("This Invoice WAS SUCCESSFULLY CREATED. There was an error printing the Invoice. Please reprint invoice at the Invoice Screen. Do not Invoice this sales order again.","Error Printing Invoice",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
                                }
                                Cursor = System.Windows.Forms.Cursors.Default;
                                if (MessageBox.Show("Invoice number " + aReturn[1].ToString().Trim() + " is created", "Message Box", MessageBoxButtons.OK, MessageBoxIcon.Information) == DialogResult.OK)
                                {
                                    cmdNewOrder_Click(null, null);
                                }
                            }
                            else
                            {
                                MessageBox.Show("Error: " + aReturn[1] + "\r\n\r\n Error Number: " + aReturn[0], "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                return;
                            }
                        }
                    }
                    else
                    {
                        MessageBox.Show("No lines to invoice", "No Invoice Lines", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    cmdSaveOrder.Enabled = false;
                }
            }

            else
            {
                using (Forms.InvoiceOrder frmInvoice = new Solsage_Process_Management_System.Forms.InvoiceOrder())
                {
                    frmInvoice.frmSalesOrder = this;
                    frmInvoice.sDocNumber = txtNumber.Text;
                    frmInvoice.sCustomerCode = txtCustomerCode.Text;
                    frmInvoice.sCustomerDescription = txtCustomerDescription.Text;
                    frmInvoice.sDiscountPerc = txtDiscount.Text;
                    frmInvoice.sDeliveryDate = dtDeliveryDate.Value.ToString("dd/MM/yyyy");
                    frmInvoice.sOrderNumber = txtOrderNumber.Text;
                    frmInvoice.sSiteName = selAddresses.Text.Trim();
                    frmInvoice.frmMain = ((Main)this.MdiParent);
                    if (frmInvoice.ShowDialog() == DialogResult.OK)
                    {

                        loadSalesOrder(txtNumber.Text);

                    }
                }
            }
        }
Exemplo n.º 8
0
        private void InvoiceGeneration()
        {
            string[] aResultString = new string[0];
            string[] aInvoiceErrors = new string[0];
            this.SyncObject = this;

            //Is invoice date in current financial period
            dtInvoiceDate.Value = new DateTime(dtInvoiceDate.Value.Year, dtInvoiceDate.Value.Month, dtInvoiceDate.Value.Day, 0, 0, 0);
            if (Convert.ToDateTime(dtInvoiceDate.Value) > Convert.ToDateTime(dtCurrPeriodEnd.Value) || Convert.ToDateTime(dtInvoiceDate.Value) < Convert.ToDateTime(dtCurrPeriodStart.Value))
            {
                MessageBox.Show("The invoice date " + Convert.ToDateTime(dtInvoiceDate.Value).ToString("dd/MM/yyyy") + " does not fall in the current period.");
            }
            else
            {
                Solsage_Process_Management_System.Classes.Generate clGenerate = new Solsage_Process_Management_System.Classes.Generate();
                int iInstruction = 0;
                int iRowCount = 0;
                //Get RowCount
                for (int i = 0; i < dgOpenSalesOrder.Rows.Count; i++)
                {
                    if (dgOpenSalesOrder.Rows[i].Cells["chkInvoice"].Value == chkInvoice.TrueValue)
                    {
                        iRowCount++;
                    }
                }
                InitProgressBar(iRowCount);

                //loop through all open sales orders
                for (int i = 0; i < dgOpenSalesOrder.Rows.Count; i++)
                {
                    if (Global.sSalesOrderType.Trim() == "Only Long Term")
                    {
                        string sSqlHH = "";
                        if (dgOpenSalesOrder.Rows[i].Cells["chkInvoice"].Value == chkInvoice.TrueValue)
                        {
                            if (dgOpenSalesOrder.Rows[i].Cells["chkFutureToActive"].Value == chkFutureToActive.TrueValue)
                            {
                                iInstruction = 1; //Invoice and convert Future Sales Order to Active order
                            }
                            if (dgOpenSalesOrder.Rows[i].Cells["chkActiveToStanding"].Value == chkActiveToStanding.TrueValue)
                            {
                                iInstruction = 2; //Invoice and convert Active order to standing order
                            }
                            if (dgOpenSalesOrder.Rows[i].Cells["chkClose"].Value == chkClose.TrueValue)
                            {
                                iInstruction = 3; //Invoice and close order (remove all lines)
                            }

                            //Build array to identify item types to invoice
                            string[] aItemTypeAction = new string[4];
                            if (chkInvoiceLeaseItems.Checked) //Invoice Lease Items
                                aItemTypeAction[0] += "1";
                            else
                                aItemTypeAction[0] += "0";

                            if (chkInvoiceReturnConsumable.Checked) //Invoice Returnable consumables
                                aItemTypeAction[1] += "1";
                            else
                                aItemTypeAction[1] += "0";

                            if (chkInvoiceConsumable.Checked) //Invoice Consumables
                                aItemTypeAction[2] += "1";
                            else
                                aItemTypeAction[2] += "0";

                            if (chkReturnedItems.Checked) //Invoice Returned Items
                                aItemTypeAction[3] += "1";
                            else
                                aItemTypeAction[3] += "0";

                            //////////////////
                            //Generate invoice
                            //////////////////

                            string sMonthEndType = "";
                            if (chkSalesOrderValues.Checked)
                                sMonthEndType = "ValuesFromSalesOrder";

                            try
                            {
                                string sResult = clGenerate.CreateCustomerDocument(dgOpenSalesOrder.Rows[i].Cells["clSalesOrderNum"].Value.ToString(), iInstruction, Convert.ToDateTime(dtInvoiceUpToDate.Value), Convert.ToDateTime(dtInvoiceDate.Value), aItemTypeAction, this, sMonthEndType);

                            }
                            catch (Exception Ex)
                            {
                                Array.Resize<string>(ref aInvoiceErrors, aInvoiceErrors.Length + 1);
                                aInvoiceErrors[aInvoiceErrors.Length - 1] = dgOpenSalesOrder.Rows[i].Cells["clSalesOrderNum"].Value.ToString();
                            }

                        }

                        else if (dgOpenSalesOrder.Rows[i].Cells["chkFutureToActive"].Value == chkFutureToActive.TrueValue) //Convert Future Sales Order to Active order NO invoice
                        {
                            using (PsqlConnection oConn = new PsqlConnection(Solsage_Process_Management_System.Classes.Connect.sConnStr))
                            {
                                oConn.Open();
                                sSqlHH = "update SOLHH set Type = 0 where DocNumber = '" + dgOpenSalesOrder.Rows[i].Cells["clSalesOrderNum"].Value.ToString() + "'";
                                int iReturnHH = Solsage_Process_Management_System.Classes.Connect.getDataCommand(sSqlHH, oConn).ExecuteNonQuery();
                                oConn.Dispose();
                            }
                        }
                        else if (dgOpenSalesOrder.Rows[i].Cells["chkActiveToStanding"].Value == chkActiveToStanding.TrueValue) //convert Active order to standing order NO Invoice
                        {
                            using (PsqlConnection oConn = new PsqlConnection(Solsage_Process_Management_System.Classes.Connect.sConnStr))
                            {
                                oConn.Open();
                                sSqlHH = "update SOLHH set Type = 1 where DocNumber = '" + dgOpenSalesOrder.Rows[i].Cells["clSalesOrderNum"].Value.ToString() + "'";
                                int iReturnHH = Solsage_Process_Management_System.Classes.Connect.getDataCommand(sSqlHH, oConn).ExecuteNonQuery();
                                oConn.Dispose();
                            }
                        }
                        else if (dgOpenSalesOrder.Rows[i].Cells["chkClose"].Value == chkClose.TrueValue) //close order (remove all lines) NO Invoice
                        {
                            using (PsqlConnection oConn = new PsqlConnection(Solsage_Process_Management_System.Classes.Connect.sConnStr))
                            {
                                oConn.Open();
                                sSqlHH = "update SOLHH set Type = 3, Status = 3 where DocNumber = '" + dgOpenSalesOrder.Rows[i].Cells["clSalesOrderNum"].Value.ToString() + "'";
                                int iReturnHH = Solsage_Process_Management_System.Classes.Connect.getDataCommand(sSqlHH, oConn).ExecuteNonQuery();
                                oConn.Dispose();
                            }
                            //Clear Inventory's UserDefText  Fields
                            using (PsqlConnection oConnHistLine = new PsqlConnection(Solsage_Process_Management_System.Classes.Connect.sPastelConnStr))
                            {
                                oConnHistLine.Open();

                                string sSql = "update Inventory set UserDefText01 = '', UserDefText02 = '', UserDefText03 = '' where UserDefText02 = '" + dgOpenSalesOrder.Rows[i].Cells["clSalesOrderNum"].Value.ToString() + "'";
                                int iReturn = Solsage_Process_Management_System.Classes.Connect.getDataCommand(sSql, oConnHistLine).ExecuteNonQuery();

                                oConnHistLine.Dispose();
                            }
                        }
                        StepProgressBar();
                    }
                    else if (Global.sSalesOrderType.Trim() == "Long Term AND Short Term")
                    {
                        //only do long term sales order so check if this sales order is long term.

                        if (dgOpenSalesOrder.Rows[i].Cells["clSalesOrderType"].Value.ToString().Trim() == "1")
                        {

                            string sSqlHH = "";
                            if (dgOpenSalesOrder.Rows[i].Cells["chkInvoice"].Value == chkInvoice.TrueValue)
                            {
                                if (dgOpenSalesOrder.Rows[i].Cells["chkFutureToActive"].Value == chkFutureToActive.TrueValue)
                                {
                                    iInstruction = 1; //Invoice and convert Future Sales Order to Active order
                                }
                                if (dgOpenSalesOrder.Rows[i].Cells["chkActiveToStanding"].Value == chkActiveToStanding.TrueValue)
                                {
                                    iInstruction = 2; //Invoice and convert Active order to standing order
                                }
                                if (dgOpenSalesOrder.Rows[i].Cells["chkClose"].Value == chkClose.TrueValue)
                                {
                                    iInstruction = 3; //Invoice and close order (remove all lines)
                                }

                                //Build array to identify item types to invoice
                                string[] aItemTypeAction = new string[4];
                                if (chkInvoiceLeaseItems.Checked) //Invoice Lease Items
                                    aItemTypeAction[0] += "1";
                                else
                                    aItemTypeAction[0] += "0";

                                if (chkInvoiceReturnConsumable.Checked) //Invoice Returnable consumables
                                    aItemTypeAction[1] += "1";
                                else
                                    aItemTypeAction[1] += "0";

                                if (chkInvoiceConsumable.Checked) //Invoice Consumables
                                    aItemTypeAction[2] += "1";
                                else
                                    aItemTypeAction[2] += "0";

                                if (chkReturnedItems.Checked) //Invoice Returned Items
                                    aItemTypeAction[3] += "1";
                                else
                                    aItemTypeAction[3] += "0";

                                //////////////////
                                //Generate invoice
                                //////////////////

                                string sMonthEndType = "";
                                if (chkSalesOrderValues.Checked)
                                    sMonthEndType = "ValuesFromSalesOrder";

                                try
                                {
                                    string sResult = clGenerate.CreateCustomerDocument(dgOpenSalesOrder.Rows[i].Cells["clSalesOrderNum"].Value.ToString(), iInstruction, Convert.ToDateTime(dtInvoiceUpToDate.Value), Convert.ToDateTime(dtInvoiceDate.Value), aItemTypeAction, this, sMonthEndType);

                                }
                                catch (Exception Ex)
                                {
                                    Array.Resize<string>(ref aInvoiceErrors, aInvoiceErrors.Length + 1);
                                    aInvoiceErrors[aInvoiceErrors.Length - 1] = dgOpenSalesOrder.Rows[i].Cells["clSalesOrderNum"].Value.ToString();
                                }

                            }

                            else if (dgOpenSalesOrder.Rows[i].Cells["chkFutureToActive"].Value == chkFutureToActive.TrueValue) //Convert Future Sales Order to Active order NO invoice
                            {
                                using (PsqlConnection oConn = new PsqlConnection(Solsage_Process_Management_System.Classes.Connect.sConnStr))
                                {
                                    oConn.Open();
                                    sSqlHH = "update SOLHH set Type = 0 where DocNumber = '" + dgOpenSalesOrder.Rows[i].Cells["clSalesOrderNum"].Value.ToString() + "'";
                                    int iReturnHH = Solsage_Process_Management_System.Classes.Connect.getDataCommand(sSqlHH, oConn).ExecuteNonQuery();
                                    oConn.Dispose();
                                }
                            }
                            else if (dgOpenSalesOrder.Rows[i].Cells["chkActiveToStanding"].Value == chkActiveToStanding.TrueValue) //convert Active order to standing order NO Invoice
                            {
                                using (PsqlConnection oConn = new PsqlConnection(Solsage_Process_Management_System.Classes.Connect.sConnStr))
                                {
                                    oConn.Open();
                                    sSqlHH = "update SOLHH set Type = 1 where DocNumber = '" + dgOpenSalesOrder.Rows[i].Cells["clSalesOrderNum"].Value.ToString() + "'";
                                    int iReturnHH = Solsage_Process_Management_System.Classes.Connect.getDataCommand(sSqlHH, oConn).ExecuteNonQuery();
                                    oConn.Dispose();
                                }
                            }
                            else if (dgOpenSalesOrder.Rows[i].Cells["chkClose"].Value == chkClose.TrueValue) //close order (remove all lines) NO Invoice
                            {
                                using (PsqlConnection oConn = new PsqlConnection(Solsage_Process_Management_System.Classes.Connect.sConnStr))
                                {
                                    oConn.Open();
                                    sSqlHH = "update SOLHH set Type = 3, Status = 3 where DocNumber = '" + dgOpenSalesOrder.Rows[i].Cells["clSalesOrderNum"].Value.ToString() + "'";
                                    int iReturnHH = Solsage_Process_Management_System.Classes.Connect.getDataCommand(sSqlHH, oConn).ExecuteNonQuery();
                                    oConn.Dispose();
                                }
                                //Clear Inventory's UserDefText  Fields
                                using (PsqlConnection oConnHistLine = new PsqlConnection(Solsage_Process_Management_System.Classes.Connect.sPastelConnStr))
                                {
                                    oConnHistLine.Open();

                                    string sSql = "update Inventory set UserDefText01 = '', UserDefText02 = '', UserDefText03 = '' where UserDefText02 = '" + dgOpenSalesOrder.Rows[i].Cells["clSalesOrderNum"].Value.ToString() + "'";
                                    int iReturn = Solsage_Process_Management_System.Classes.Connect.getDataCommand(sSql, oConnHistLine).ExecuteNonQuery();

                                    oConnHistLine.Dispose();
                                }
                            }
                            StepProgressBar();
                        }
                    }
                }

                StopProgress();
                try
                {
                    string sInvoiceErrors = "";
                    for (int i = 0; i < aInvoiceErrors.Length; i++)
                    {
                        sInvoiceErrors += "," + aInvoiceErrors[i];
                    }
                    sInvoiceErrors = sInvoiceErrors.Remove(0, 1);
                    MessageBox.Show("Errors were found in the following Documents: " + sInvoiceErrors);
                }
                catch
                {
                }
            }
        }
Exemplo n.º 9
0
        public void cmdCreateInvoice_Click(object sender, EventArgs e)
        {
            string[] aInvoiceLines = new string[0];
            ArrayList alLinesdata = new ArrayList();
            string[] aGetnewlinedata = new string[8];
            if (Global.bAutoInvoiceOnReturn || MessageBox.Show("This will create a Tax Invoice. Are You Sure?", "Create Invoice", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)//don't ask are you sure if global invoicing is on
            {
                foreach (DataGridViewRow dgRow in dgInvoiceItems.Rows)
                {
                    if (dgRow.Cells["clInvoice"] != null && dgRow.Cells["clInvoice"].Value.ToString() == "True")
                    {
                        addInvoiceLine(sDocNumber, dgRow.Cells["clItemCode"].Value.ToString(), dgRow.Cells["clNumber"].Value.ToString(),ref aInvoiceLines, dgRow.Cells["clTypeCode"].Value.ToString(), dgRow.Cells["clDeliveryDate"].Value.ToString(), dgRow.Cells["clReturnDate"].Value.ToString());
                    }
                }
            }
            else
            {
                if (dgInvoiceItems.RowCount > 0)
                {
                    dgInvoiceItems.CurrentCell = dgInvoiceItems.Rows[0].Cells["clInvoice"];
                    this.ActiveControl = dgInvoiceItems;
                }
            }

            //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Do Invoicing !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
            if (aInvoiceLines.Length > 0)
            {
                Solsage_Process_Management_System.Classes.Generate clsGenerate = new Solsage_Process_Management_System.Classes.Generate();
                string sNewCustomer = ""; //Empty sNewCustomer varaible states that no change has been made
                if (sCustomerCode.Trim() != txtCustomerCode.Text.Trim())
                {
                    sNewCustomer = txtCustomerCode.Text.Trim(); //customer has changed
                }

                string sNewSalesmanCode = "";//Empty sNewSalesmanCode varaible states that no change has been made
                if (Global.sLogedInUserCode.Trim() != txtSalesCode.Text.Trim())
                {
                    sNewSalesmanCode = txtSalesCode.Text.Trim();//Salesman has changed
                }

                string sNewOrderNumber = "";//Empty sNewOrderNumber varaible states that no change has been made
                if (sOrderNumber.Trim() != txtOrderNumber.Text.Trim())
                {
                    sNewOrderNumber = txtOrderNumber.Text.Trim();//Ordernumber has changed
                }
                using (PsqlConnection oPasConn = new PsqlConnection(Solsage_Process_Management_System.Classes.Connect.sPastelConnStr))
                {
                    oPasConn.Open();

                    string[] aReturn = clsGenerate.CreateCustomerDocument(sDocNumber, 3, aInvoiceLines, sNewCustomer, sNewSalesmanCode, sNewOrderNumber, "", DateTime.Now, oPasConn, "", alLinesdata, sSiteName);
                    if (aReturn[0] == "0")
                    {
                        Cursor = System.Windows.Forms.Cursors.WaitCursor;
                        if (Global.sInvoiceTemplate == "Kings Hire")
                        {
                            if (printDialog1.ShowDialog() == DialogResult.OK)
                            {
                                Solsage_Process_Management_System.Classes.Functions.printInvoice(aReturn[1], true, bPrintToDepot, Global.sLogedInUserCode, printDialog1);
                            }

                        }
                        else
                        {
                            PrintDialog pdPrint = new PrintDialog();
                            Solsage_Process_Management_System.Classes.Functions.printInvoice(aReturn[1], true, bPrintToDepot, Global.sLogedInUserCode, pdPrint);
                        }

                        sInvoiceNumber = aReturn[1];
                        if (bPrintToDepot)
                        {
                            string sFilename = Solsage_Process_Management_System.Classes.Functions .sDepotFilename;
                            Solsage_Process_Management_System.Forms.SendToDepot frmDepot = new Solsage_Process_Management_System.Forms.SendToDepot();
                            frmDepot.sFilename = sFilename;
                            frmDepot.sHostAddress = ConfigurationSettings.AppSettings.Get("PrintToDepotAddress").ToString();
                            frmDepot.sFtpUsername = ConfigurationSettings.AppSettings.Get("ftpUsername").ToString();
                            frmDepot.sFtpPassword = ConfigurationSettings.AppSettings.Get("ftpPassword").ToString();

                            frmDepot.ShowDialog();
                        }
                        Cursor = System.Windows.Forms.Cursors.Default;
                    }
                    else
                    {
                        MessageBox.Show("Error: " + aReturn[1] + "\r\n\r\n Error Number: " + aReturn[0], "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }

                    //Should not be deleted, already happens on Generate
                    //for (int iLines = 0; iLines < aInvoiceLines.Length; iLines++) //only remove from salesorder if invoiced
                    //{
                    //    string sMyLine = aInvoiceLines[iLines];
                    //    sMyLine = sMyLine.Remove(sMyLine.IndexOf("^"), sMyLine.Length - sMyLine.IndexOf("^"));
                    //    if (sMyLine != null && sMyLine.Trim() != "")
                    //    {
                    //        aReturn = clsSDK.EditPastelDocument(sMyLine, 102, sDocNumber, "D", Global.sDataPath).Split("|".ToCharArray());
                    //    }
                    //}
                }
            }

            int iRemainingRows = Functions.GetLiquidSalesLinesQty(sDocNumber);
            if (iRemainingRows == 0)
            {
                using (PsqlConnection oConn = new PsqlConnection(Solsage_Process_Management_System.Classes.Connect.sConnStr))
                {
                    oConn.Open();
                    string sSql = "";
                    int iRet = 0;
                    if (MessageBox.Show("There are no more lines in this order. Do you want to close this order?", "Close Order?", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                         sSql = "UPDATE SOLHH SET ";
                        sSql += " Status = 3";
                        sSql += " WHERE DocNumber = '" + sDocNumber + "' ";
                         iRet = Solsage_Process_Management_System.Classes.Connect.getDataCommand(sSql, oConn).ExecuteNonQuery();
                        frmSalesOrder.setSalesOrderStatus(3);
                    }
                    else
                    {
                         sSql = "UPDATE SOLHH SET ";
                        sSql += " Status = 2 ";
                        sSql += " WHERE DocNumber = '" + sDocNumber + "' ";
                        iRet = Solsage_Process_Management_System.Classes.Connect.getDataCommand(sSql, oConn).ExecuteNonQuery();
                        frmSalesOrder.setSalesOrderStatus(2);

                    }
                    oConn.Dispose();
                }
            }
            this.DialogResult = DialogResult.OK;
            this.Close();
            //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
        }