Пример #1
0
        private void UpdateWorkOrder(int workOrderID, string woNumber, string woType, string paymentMethod, double?version, string rush, string rushReason,
                                     string remarks, DateTime?issueDate, DateTime?dueDate, string cloneType, enterprise.Work_Order__c preWONumber, string siteCheckPurpose, string siteCheckPurposeAsOther, string sfWorkOrderID, double?amount, double?reviseWOCount, enterprise.User accountExecutive)
        {
            try
            {
                var workOrder = _db.Sales_JobMasterList_WO.Where(x => x.woID == workOrderID).FirstOrDefault();
                if (workOrder != null)
                {
                    switch (woType)
                    {
                    case "Production":
                        workOrder.woType = 10;
                        break;

                    case "Service":
                        workOrder.woType = 20;
                        break;

                    case "Site Check":
                        workOrder.woType = 30;
                        break;

                    default:
                        break;
                    }

                    switch (paymentMethod)
                    {
                    case "C.O.D (Invoice Attached)":
                        workOrder.PayMethods = 10;
                        break;

                    case "Invoice Mail Out By Office":
                        workOrder.PayMethods = 20;
                        break;

                    case "Installers Give Invoice To Client":
                        workOrder.PayMethods = 30;
                        break;

                    case "No Charge-Other":
                        workOrder.PayMethods = 40;
                        break;

                    case "No Charge-Mistakes":
                        workOrder.PayMethods = 41;
                        break;

                    case "No Charge-Under Warranty":
                        workOrder.PayMethods = 42;
                        break;

                    case "No Charge-Company Give Out As Gift":
                        workOrder.PayMethods = 43;
                        break;

                    case "No Charge-Sample":
                        workOrder.PayMethods = 44;
                        break;

                    case "No Charge-For Company Internal Use":
                        workOrder.PayMethods = 45;
                        break;

                    case "Decide By Installer":
                        workOrder.PayMethods = 46;
                        break;

                    case "PJ":
                        workOrder.PayMethods = 50;
                        break;

                    default:
                        break;
                    }

                    if (version != null)
                    {
                        workOrder.woRev = Convert.ToByte(version);
                    }

                    switch (rush)
                    {
                    case "Yes":
                        workOrder.rush       = true;
                        workOrder.rushReason = rushReason;
                        break;

                    case "No":
                        workOrder.rush = false;
                        break;

                    default:
                        break;
                    }

                    workOrder.Remarks = remarks;

                    if (issueDate != null)
                    {
                        workOrder.issuedDate = (DateTime)issueDate;
                    }
                    if (dueDate != null)
                    {
                        workOrder.DeadLine = (DateTime)dueDate;
                    }

                    if (amount != null)
                    {
                        workOrder.WorkorderAmount = Convert.ToDouble(amount);
                    }

                    if (accountExecutive != null)
                    {
                        FsEmployee poEmployee = new FsEmployee(accountExecutive.CommunityNickname);
                        if (poEmployee.EmployeeNumber > 0)
                        {
                            workOrder.Sales = poEmployee.EmployeeNumber;
                        }
                    }

                    switch (cloneType)
                    {
                    case "Redo":
                        workOrder.rush = true;
                        workOrder.reDo = true;

                        if (reviseWOCount != null)
                        {
                            if (reviseWOCount > 0)
                            {
                                workOrder.revise    = true;
                                workOrder.reviseVer = Convert.ToInt16(reviseWOCount);
                            }
                            else
                            {
                                workOrder.revise    = false;
                                workOrder.reviseVer = null;
                            }
                        }
                        else
                        {
                            workOrder.revise    = false;
                            workOrder.reviseVer = null;
                        }

                        workOrder.RedoOfWoNumbers = preWONumber != null ? preWONumber.Work_Order_Number__c : "";
                        //workOrder.WorkorderNumber = woNumber;
                        if (version != null)
                        {
                            workOrder.redoVer = Convert.ToInt16(version);
                        }
                        break;

                    case "Revise":
                        workOrder.rush    = true;
                        workOrder.revise  = true;
                        workOrder.reDo    = false;
                        workOrder.redoVer = null;

                        workOrder.RedoOfWoNumbers = preWONumber != null ? preWONumber.Work_Order_Number__c : "";
                        //workOrder.WorkorderNumber = preWONumber != null ? preWONumber.Name : "";
                        if (version != null)
                        {
                            workOrder.reviseVer = Convert.ToInt16(version);
                        }
                        break;

                    case "New":
                        workOrder.revise          = false;
                        workOrder.reviseVer       = null;
                        workOrder.reDo            = false;
                        workOrder.redoVer         = null;
                        workOrder.RedoOfWoNumbers = "";
                        //workOrder.WorkorderNumber = woNumber;
                        break;

                    default:
                        break;
                    }

                    workOrder.WorkorderNumber = woNumber;

                    _db.Entry(workOrder).State = EntityState.Modified;
                    _db.SaveChanges();
                }

                if (woType == "Site Check")
                {
                    int siteCheckID = CommonMethods.GetMISID(TableName.WO_Sitecheck_Purpose, sfWorkOrderID, salesForceProjectID);
                    if (siteCheckID == 0)
                    {
                        InsertNewSiteCheckPurpose(workOrderID, siteCheckPurpose, siteCheckPurposeAsOther);
                        int newId = SqlCommon.GetNewlyInsertedRecordID(TableName.WO_Sitecheck_Purpose);
                        if (newId > 0)
                        {
                            CommonMethods.InsertToMISSalesForceMapping(TableName.WO_Sitecheck_Purpose, sfWorkOrderID, newId.ToString(), salesForceProjectID);
                        }
                    }
                    else
                    {
                        UpdateSiteCheckPurpose(siteCheckID, siteCheckPurpose, siteCheckPurposeAsOther);
                    }
                }
            }
            catch (Exception e)
            {
                LogMethods.Log.Error("UpdateWorkOrder:Error:" + e.Message);
            }
        }
Пример #2
0
        private void UpdateInvoice(int invoiceID, string invoiceNumber, DateTime?issueDate, int sale, string term, string contractNo,
                                   string shipMethod, DateTime?contractDate, string taxOption, double?tax, double?deposit, double?discount, string invoiceType, string workOrderList, string currency, enterprise.User accountExecutive, enterprise.User projectCoordinator, enterprise.Quotation__c po, string suffix, double?version, String status, double?subTotal)
        {
            try
            {
                var invoice = _db.Sales_JobMasterList_Invoice.Where(x => x.invoiceID == invoiceID).FirstOrDefault();
                if (invoice != null)
                {
                    invoice.invoiceNo = invoiceNumber;
                    if (issueDate != null)
                    {
                        invoice.invoiceDate = issueDate;
                    }
                    invoice.Sales = sale;

                    if (currency != null)
                    {
                        invoice.Currency = currency;
                    }

                    if (suffix != null)
                    {
                        invoice.NameSurfix = suffix;
                    }

                    if (version != null)
                    {
                        invoice.Revision = Convert.ToByte(version);
                    }

                    if (status != null)
                    {
                        if (status.Equals("Pending", StringComparison.OrdinalIgnoreCase))
                        {
                            invoice.iStatus = 2002;
                        }
                        else if (status.Equals("Rejected", StringComparison.OrdinalIgnoreCase))
                        {
                            invoice.iStatus = 2004;
                        }
                        else if (status.Equals("Approved", StringComparison.OrdinalIgnoreCase))
                        {
                            invoice.iStatus = 2003;
                        }
                        else
                        {
                            invoice.iStatus = 2001;
                        }
                    }
                    else
                    {
                        invoice.iStatus = 2001;
                    }


                    if (!string.IsNullOrEmpty(term))
                    {
                        switch (term)
                        {
                        case "Cash On Delivery":
                            invoice.Term = 0;
                            break;

                        case "Customer Net 7 Days":
                            invoice.Term = 7;
                            break;

                        case "Customer Net 10 Days":
                            invoice.Term = 10;
                            break;

                        case "Customer Net 15 Days":
                            invoice.Term = 15;
                            break;

                        case "Customer Net 20 Days":
                            invoice.Term = 20;
                            break;

                        case "Customer Net 30 Days":
                            invoice.Term = 30;
                            break;

                        case "Customer Net 45 Days":
                            invoice.Term = 45;
                            break;

                        case "Customer Net 60 Days":
                            invoice.Term = 60;
                            break;

                        case "Customer Net 180 Days":
                            invoice.Term = 180;
                            break;

                        case "Due Upon Receipt":
                            invoice.Term = 100;
                            break;

                        case "75 3WD":
                            invoice.Term = 200;
                            break;

                        default:
                            invoice.Term = 1000;
                            break;
                        }
                    }

                    invoice.ContractNo = contractNo;
                    if (!string.IsNullOrEmpty(shipMethod))
                    {
                        invoice.ShipVia = shipMethod;
                    }

                    if (contractDate != null)
                    {
                        invoice.contractDate = contractDate;
                    }

                    switch (taxOption)
                    {
                    case "HST":
                        invoice.TaxOption = (short)NTaxOption.HST;
                        break;

                    case "HST-BC":
                        invoice.TaxOption = (int)NTaxOption.HstBC;
                        break;

                    case "GST Only":
                        invoice.TaxOption = (int)NTaxOption.GstOnly;
                        break;

                    case "GST & PST":
                        invoice.TaxOption = (int)NTaxOption.GstAndPst;
                        break;

                    case "Manually":
                        invoice.TaxOption = (int)NTaxOption.Manually;
                        if (tax != null)
                        {
                            invoice.pstAmount = Convert.ToDecimal(tax);
                        }
                        break;

                    case "No Tax":
                        invoice.TaxOption = (int)NTaxOption.NoTax;
                        break;

                    default:
                        break;
                    }

                    if (deposit != null)
                    {
                        invoice.Deposit = Convert.ToDecimal(deposit);
                    }

                    if (discount != null)
                    {
                        invoice.Discount = (-1) * Convert.ToDecimal(discount);
                    }

                    if (invoiceType != null)
                    {
                        switch (invoiceType)
                        {
                        case "Regular":
                            invoice.invoiceType = 1;
                            break;

                        case "Proforma":
                            invoice.invoiceType = 2;
                            break;

                        default:
                            invoice.invoiceType = 3;
                            break;
                        }
                    }

                    if (accountExecutive != null)
                    {
                        FsEmployee poEmployee = new FsEmployee(accountExecutive.CommunityNickname);
                        if (poEmployee.EmployeeNumber > 0)
                        {
                            invoice.Sales = poEmployee.EmployeeNumber;
                        }
                    }

                    if (projectCoordinator != null)
                    {
                        FsEmployee poEmployee = new FsEmployee(projectCoordinator.CommunityNickname);
                        if (poEmployee.EmployeeNumber > 0)
                        {
                            invoice.SA1 = poEmployee.EmployeeNumber;
                        }
                    }

                    if (po != null && po.PO_No__c != null)
                    {
                        invoice.po = po.PO_No__c;
                    }
                    if (subTotal != null)
                    {
                        invoice.InvoiceAmount = Convert.ToDecimal(subTotal);
                    }
                    string workOrders = "";
                    if (!string.IsNullOrEmpty(workOrderList))
                    {
                        char[]   delimiters = new char[] { '\n', ' ', ',' };
                        string[] items      = workOrderList.Split(delimiters);
                        if (items.Length != 0)
                        {
                            workOrders = string.Join(",", items);
                        }
                    }
                    invoice.Workorders = workOrders;

                    _db.Entry(invoice).State = EntityState.Modified;
                    _db.SaveChanges();
                }
            }
            catch (Exception e)
            {
                LogMethods.Log.Error("UpdateInvoice:Error:" + e.Message);
            }
        }
Пример #3
0
        /// <summary>
        /// Edit a project
        /// </summary>
        private void UpdateProject(int jobID, DateTime?targetDate, int sales, string jobTitle, string salesType, enterprise.User AE, string productLine, enterprise.User projectCoordinatorName)
        {
            using (var Connection = new SqlConnection(MISServiceConfiguration.ConnectionString))
            {
                string UpdateString  = "UPDATE Sales_JobMasterList SET targetDate = @targetDate, sales = @sales, jobTitle = @jobTitle, salesType = @salesType, isBidToProject = @isBidToProject, AETM = @AETM, ProductLine = @ProductLine, sa1ID = @sa1ID WHERE (jobID = @jobID)";
                var    UpdateCommand = new SqlCommand(UpdateString, Connection);
                if (targetDate != null)
                {
                    UpdateCommand.Parameters.Add("@targetDate", SqlDbType.DateTime).Value = targetDate;
                }
                else
                {
                    UpdateCommand.Parameters.Add("@targetDate", SqlDbType.DateTime).Value = DBNull.Value;
                }

                switch (salesType)
                {
                case SalesType.Repeat:
                    UpdateCommand.Parameters.AddWithValue("@salesType", 0);
                    UpdateCommand.Parameters.AddWithValue("@isBidToProject", 0);
                    break;

                case SalesType.Bid:
                    UpdateCommand.Parameters.AddWithValue("@salesType", 2);
                    UpdateCommand.Parameters.AddWithValue("@isBidToProject", 1);
                    break;

                default:
                    UpdateCommand.Parameters.AddWithValue("@salesType", 1);
                    UpdateCommand.Parameters.AddWithValue("@isBidToProject", 0);
                    break;
                }

                UpdateCommand.Parameters.Add("@jobTitle", SqlDbType.VarChar, 150).Value = jobTitle;
                UpdateCommand.Parameters.Add("@jobID", SqlDbType.Int).Value             = jobID;

                if (AE != null)
                {
                    //string un = CommonMethods.GetUserName(AE.Id);
                    string     un         = AE.CommunityNickname == null ? "" :  AE.CommunityNickname;
                    FsEmployee fsEmployee = new FsEmployee(un);
                    if (fsEmployee.EmployeeNumber > 0)
                    {
                        UpdateCommand.Parameters.AddWithValue("@AETM", fsEmployee.EmployeeNumber);
                        UpdateCommand.Parameters.Add("@sales", SqlDbType.Int).Value = fsEmployee.EmployeeNumber;
                    }
                    else
                    {
                        LogMethods.Log.Error("UpdateProject:Error:" + "User Name: " + un + " does not exist in database");
                        UpdateCommand.Parameters.AddWithValue("@AETM", 0);
                        UpdateCommand.Parameters.Add("@sales", SqlDbType.Int).Value = sales;
                    }
                }
                else
                {
                    UpdateCommand.Parameters.AddWithValue("@AETM", 0);
                    UpdateCommand.Parameters.Add("@sales", SqlDbType.Int).Value = sales;
                }

                if (productLine != null)
                {
                    switch (productLine)
                    {
                    case "Signage":
                        UpdateCommand.Parameters.AddWithValue("@ProductLine", 1);
                        break;

                    default:
                        UpdateCommand.Parameters.AddWithValue("@ProductLine", 10);
                        break;
                    }
                }
                else
                {
                    UpdateCommand.Parameters.AddWithValue("@ProductLine", 1);
                }

                string     op         = (projectCoordinatorName == null ? "" : projectCoordinatorName.CommunityNickname);
                FsEmployee poEmployee = new FsEmployee(op);
                if (projectCoordinatorName != null && poEmployee.EmployeeNumber > 0)
                {
                    UpdateCommand.Parameters.AddWithValue("@sa1ID", poEmployee.EmployeeNumber);
                }
                else
                {
                    UpdateCommand.Parameters.AddWithValue("@sa1ID", 110);
                }

                try
                {
                    Connection.Open();
                    UpdateCommand.ExecuteNonQuery();
                    LogMethods.Log.Debug("UpdateProject:Debug:" + "Done");
                }
                catch (SqlException ex)
                {
                    LogMethods.Log.Error("UpdateProject:Error:" + ex.Message);
                }
                finally
                {
                    Connection.Close();
                }
            }
        }
Пример #4
0
        private void UpdateQuote(int quoteRevID, double?subTotal, double?discountAmount, double?version, string taxOption, double?taxRate, string term, string currency, enterprise.User po)
        {
            try
            {
                var sales_JobMasterList_quoteRev = _db.Sales_JobMasterList_QuoteRev.Where(x => x.quoteRevID == quoteRevID).FirstOrDefault();
                if (sales_JobMasterList_quoteRev != null)
                {
                    if (discountAmount != null)
                    {
                        sales_JobMasterList_quoteRev.DiscountAmount = Convert.ToDecimal(discountAmount);
                    }

                    if (version != null)
                    {
                        sales_JobMasterList_quoteRev.quoteRev = Convert.ToByte(version);
                    }

                    if (currency != null)
                    {
                        sales_JobMasterList_quoteRev.Currency = currency;
                    }

                    //Updated by Victor Ng, Aug-30-2019
                    if (subTotal != null)
                    {
                        sales_JobMasterList_quoteRev.quoteAmount = Convert.ToDecimal(subTotal);
                    }
                    //

                    switch (taxOption)
                    {
                    case "HST":
                        sales_JobMasterList_quoteRev.TaxOption = (int)NTaxOption.HST;
                        break;

                    case "HST-BC":
                        sales_JobMasterList_quoteRev.TaxOption = (int)NTaxOption.HstBC;
                        break;

                    case "GST Only":
                        sales_JobMasterList_quoteRev.TaxOption = (int)NTaxOption.GstOnly;
                        break;

                    case "GST & PST":
                        sales_JobMasterList_quoteRev.TaxOption = (int)NTaxOption.GstAndPst;
                        break;

                    case "Manually":
                        sales_JobMasterList_quoteRev.TaxOption = (int)NTaxOption.Manually;
                        if (subTotal != null && discountAmount != null)
                        {
                            sales_JobMasterList_quoteRev.pstAmount = Convert.ToDecimal((subTotal - discountAmount) * Convert.ToInt16(taxRate) * 0.01);
                        }
                        break;

                    case "No Tax":
                        sales_JobMasterList_quoteRev.TaxOption = (int)NTaxOption.NoTax;
                        break;

                    default:
                        break;
                    }

                    if (!string.IsNullOrEmpty(term))
                    {
                        switch (term)
                        {
                        case "Cash On Delivery":
                            sales_JobMasterList_quoteRev.termBalance = 0;
                            break;

                        case "Customer Net 7 Days":
                            sales_JobMasterList_quoteRev.termBalance = 7;
                            break;

                        case "Customer Net 10 Days":
                            sales_JobMasterList_quoteRev.termBalance = 10;
                            break;

                        case "Customer Net 15 Days":
                            sales_JobMasterList_quoteRev.termBalance = 15;
                            break;

                        case "Customer Net 20 Days":
                            sales_JobMasterList_quoteRev.termBalance = 20;
                            break;

                        case "Customer Net 30 Days":
                            sales_JobMasterList_quoteRev.termBalance = 30;
                            break;

                        case "Customer Net 45 Days":
                            sales_JobMasterList_quoteRev.termBalance = 45;
                            break;

                        case "Customer Net 60 Days":
                            sales_JobMasterList_quoteRev.termBalance = 60;
                            break;

                        case "Customer Net 180 Days":
                            sales_JobMasterList_quoteRev.termBalance = 180;
                            break;

                        case "Due Upon Receipt":
                            sales_JobMasterList_quoteRev.termBalance = 100;
                            break;

                        case "75 3WD":
                            sales_JobMasterList_quoteRev.termBalance = 200;
                            break;

                        default:
                            sales_JobMasterList_quoteRev.termBalance = 1000;
                            break;
                        }
                    }

                    if (po != null)
                    {
                        FsEmployee poEmployee = new FsEmployee(po.CommunityNickname);
                        if (poEmployee.EmployeeNumber > 0)
                        {
                            sales_JobMasterList_quoteRev.sa1ID = poEmployee.EmployeeNumber;
                        }
                    }

                    _db.Entry(sales_JobMasterList_quoteRev).State = EntityState.Modified;
                    _db.SaveChanges();
                }
            }
            catch (Exception e)
            {
                LogMethods.Log.Error("UpdateQuote:Error:" + e.Message);
            }
        }