コード例 #1
0
ファイル: SalesOrder.cs プロジェクト: anthonied/LiquidPastel
        private void ProcessReturnItems(PsqlConnection oPasConn, PsqlConnection oSolConn, ref SalesLine slActive)
        {
            bool bInvoice = false;
            bool bUpdated = false;
            string sLine = "";
            string sSql = "";
            string[] aSalesRemoveLines = new string[0];
            int iIndex = 0;

            if (slActive.chkReturn.Checked)
            {
                //Validations
                if (Convert.ToDecimal(slActive.txtMultiplier.Text) > slActive.dMaxMultiplierValue)//check if multiplier returned is more than the original multiplier
                {
                    MessageBox.Show("You can't return more items than originally orderder. \r\n  The original order amout was: " + slActive.dMaxMultiplierValue.ToString(), "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    slActive.txtMultiplier.Parent.BackColor = Color.Red;
                    return;
                }
                else if (slActive.txtMultiplier.Text != "" && Convert.ToDecimal(slActive.txtMultiplier.Text) <= 0)
                {
                    MessageBox.Show("You can't return zero or negative item.", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    slActive.txtMultiplier.Parent.BackColor = Color.Red;
                    return;
                }
                else
                {//process returned item

                    for (int iLines = 0; iLines < aSaleslines.Length; iLines++)   //find sales line that is linked to this entry
                    {

                        DateTime dtDeliveryDate = DateTime.Now, dtReturnDate = DateTime.Now;
                        int iRet = 0;
                        bInvoice = true;
                        bUpdated = true;
                        if (slActive.sLineType == "1")//lease item
                        {
                            dtDeliveryDate = slActive.dtDelivery.Value;
                            dtReturnDate = slActive.dtReturnDate.Value;

                            sSql = "UPDATE Inventory SET "; //book this item back for rental
                            sSql += " UserDefText01 = '' ";
                            sSql += ", UserDefText02 = '' ";
                            sSql += ", UserDefText03 = '' ";
                            sSql += " WHERE ItemCode = '" + slActive.txtCode.Text + "' ";
                            iRet = Solsage_Process_Management_System.Classes.Connect.getDataCommand(sSql, oPasConn).ExecuteNonQuery();
                        }
                        if (slActive.sLineType != "Comment")
                        {
                            string sTotalQty = (Convert.ToDecimal(slActive.txtMultiplier.Text) * Convert.ToDecimal(slActive.txtQuantity.Text)).ToString("N2"); //Update Pastel directly because if updated through the SDK it gets a new linkedNum
                            sSql = "UPDATE HistoryLines SET ";
                            sSql += " Qty = " + sTotalQty.Replace(",", "");
                            sSql += ", UnitPrice = " + slActive.txtExcPrice.Text.Replace(",", "");
                            sSql += ", DiscountPercentage = " + (Convert.ToDecimal(slActive.txtDiscount.Text.Replace(",", "")) * 100).ToString();
                            sSql += " where DocumentNumber = '" + txtNumber.Text.Trim() + "' and ItemCode = '" + slActive.txtCode.Text.Trim() + "' and LinkNum = " + slActive.sPastelLineLink;
                            iRet = Solsage_Process_Management_System.Classes.Connect.getDataCommand(sSql, oPasConn).ExecuteNonQuery();

                            sSql = "UPDATE SOLHL SET "; //mark salesline as returned
                            sSql += " Status = 1";
                            sSql += ", Multiplier = " + slActive.txtMultiplier.Text.Replace(",", "");
                            sSql += ", Qty = " + slActive.txtQuantity.Text.Replace(",", "");
                            if (slActive.sLineType == "1")//lease item
                            {
                                sSql += ", DeliveryDate = '" + dtDeliveryDate.ToString("dd-MM-yyyy") + "'";
                                sSql += ", ReturnDate = '" + dtReturnDate.ToString("dd-MM-yyyy") + "'";
                            }
                            sSql += " WHERE Header = '" + txtNumber.Text + "' and ItemCode = '" + slActive.txtCode.Text.Trim() + "' and LinkNum = " + slActive.sPastelLineLink;
                            iRet = Solsage_Process_Management_System.Classes.Connect.getDataCommand(sSql, oSolConn).ExecuteNonQuery();
                            slActive.txtStatus.Text = "1";
                            addTotals();
                        }
                        #region Multiplier Test And Setup
                        //Multiplier returns
                        //If less items is returned in the multiplier field Add the remaining qty
                        bool bMultiplierPartialReturn = false;
                        string sNewLinkNum = "";
                        string[] aMultiplierDownTime = new string[0];

                        if (Convert.ToDecimal(slActive.txtMultiplier.Text) < slActive.dMaxMultiplierValue && slActive.sLineType == "1")//Less items returned and must be lease item
                        {
                            bMultiplierPartialReturn = true;
                        }

                        #endregion

                        #region Multiplier Function
                        //Multiplier returns
                        //If less items is returned in the multiplier field Add the remaining qty
                        if (bMultiplierPartialReturn)
                        {
                            string sNewQty = (slActive.dMaxMultiplierValue - Convert.ToDecimal(slActive.txtMultiplier.Text) * Convert.ToDecimal(slActive.txtQuantity.Text)).ToString();
                            //Book linked item back via invoice
                            sLine = "|"; //Cost Price
                            sLine += sNewQty + "|"; //Line Quantity
                            sLine += slActive.txtExcPrice.Text + "|"; //Exclusive Price Per Unit
                            if (slActive.txtTaxType.Text == "0")
                                sLine += (Convert.ToDecimal(slActive.txtExcPrice.Text)).ToString().Replace(",", "") + "|"; //Inclusive Price Per Unit
                            else if (slActive.txtTaxType.Text == "1")
                                sLine += (Convert.ToDecimal(slActive.txtExcPrice.Text) * 1.14m).ToString().Replace(",", "") + "|"; //Inclusive Price Per Unit
                            sLine += slActive.txtUnit.Text + "|"; //Unit
                            sLine += slActive.txtTaxType.Text + "|"; //Tax Type
                            sLine += slActive.txtDiscountType.Text + "|"; //Discount Type
                            sLine += slActive.txtDiscount.Text + "|"; //Discount %
                            sLine += slActive.txtCode.Text + "|"; //Code
                            sLine += slActive.txtDescription.Text + "|"; //Description
                            sLine += "4|"; //Line Type
                            sLine += slActive.txtStore.Text + "|"; //MultiStore
                            sLine += "|"; //CostCode
                            string[] aMultiplierReturn = clsSDK.EditPastelDocument(sLine, 102, txtNumber.Text, "I", Global.sDataPath).Split("|".ToCharArray());
                            if (aMultiplierReturn[0] != "0")
                            {
                                MessageBox.Show("Error 100.  Failed to create new multiplier row. \r\n\r\n Error " + aMultiplierReturn[1], "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                            else //Pastel row added
                            {
                                //Get new Linknum for line - must get from Pastel because downtime lines and notes is not stored in SolHL
                                sSql = "Select max(LinkNum) from HistoryLines where DocumentNumber = '" + txtNumber.Text + "'";
                                sNewLinkNum = Connect.getDataCommand(sSql, oPasConn).ExecuteScalar().ToString();
                                sSql = "INSERT into SOLHL";
                                sSql += " (Header, ItemCode, DeliveryDate, ReturnDate, Status,LinkNum, Multiplier, Qty) ";
                                sSql += " VALUES ";
                                sSql += "(";
                                sSql += "'" + txtNumber.Text.Trim() + "'";
                                sSql += ",'" + slActive.txtCode.Text + "'";
                                sSql += ", '" + slActive.dtDelivery.Value.ToString("dd-MM-yyyy") + "'";
                                sSql += ",'" + slActive.dtReturnDate.Value.ToString("dd-MM-yyyy") + "'";
                                sSql += ",0"; //status0 not returned
                                sSql += "," + sNewLinkNum;
                                sSql += "," + (slActive.dMaxMultiplierValue - Convert.ToDecimal(slActive.txtMultiplier.Text)).ToString();
                                sSql += "," + slActive.txtQuantity.Text;
                                sSql += ")";
                                int Ret = Solsage_Process_Management_System.Classes.Connect.getDataCommand(sSql, oSolConn).ExecuteNonQuery();
                                //Add Downtime to new row
                                for (int i = 0; i < aMultiplierDownTime.Length; i++)
                                {
                                    if (aMultiplierDownTime[i].Trim() != "")
                                    {
                                        string[] aEditDownReturn = clsSDK.EditPastelDocument(aMultiplierDownTime[i].Replace("~~~", sNewLinkNum.PadLeft(3, "0".ToCharArray()[0])), 102, txtNumber.Text, "I", Global.sDataPath).Split("|".ToCharArray());
                                    }
                                }
                            }
                        }
                        #endregion

                        iIndex++;
                        break;
                    }
                }
            }
            if (!bUpdated)
            {
              //  MessageBox.Show("No items were selected for return.", "No Returned Items", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else
            {
                if (Global.bAutoInvoiceOnReturn && bInvoice)//Create Invoice for Returned items
                {
                    Cursor = System.Windows.Forms.Cursors.WaitCursor;
                    using (Solsage_Process_Management_System.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);
                        //autoinvoice
                        if (chkChangeInvoice.Checked)
                        {
                            chkChangeInvoice.Checked = false;
                            if (frmInvoice.ShowDialog() == DialogResult.OK)
                            {
                                loadSalesOrder(txtNumber.Text);
                            }
                            else//Closed application
                            {
                                frmInvoice.InvoiceOrder_Load(null, null);
                                frmInvoice.cmdCreateInvoice_Click(null, null);
                                loadSalesOrder(txtNumber.Text);
                            }
                        }
                        else
                        {
                            frmInvoice.InvoiceOrder_Load(null, null);
                            frmInvoice.cmdCreateInvoice_Click(null, null);
                            loadSalesOrder(txtNumber.Text);
                        }
                    }
                    Cursor = System.Windows.Forms.Cursors.Default;
                }
            }
        }
コード例 #2
0
ファイル: SalesOrder.cs プロジェクト: anthonied/LiquidPastel
        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);

                    }
                }
            }
        }