Esempio n. 1
0
        public void Insert()
        {
            //Get working invoice Id
            var invTask = new GetInvoiceIdTask
            {
                RegisterId    = In.RegisterId,
                InvoiceStatus = InvoiceStatus.Working,
            };

            invTask.Execute();
            string invDate = Date.ToString("yyyy'-'MM'-'dd HH':'mm':'ss");

            InvoiceId = In.Id = invTask.Out;
            //Create Working Invoice
            var recordQuery = "select max(recordID) + 1 from DBA.WInvHeaders";
            int recordId    = SharedDb.PosimDb.GetInt(recordQuery);

            In.RecordId = recordId;
            //var recordId = int.Parse(recordIdstring);
            string winHdrArray = recordId + ",'" + In.Id + "','" +
                                 In.Customer.CustomerID +
                                 "','" + invDate + "','" +
                                 Date.ToString("yyyy'-'MM'-'dd") + "','" +
                                 In.Customer.Company.GetSqlCompatible(false) + "','" + In.Customer.FirstName.GetSqlCompatible(false) +
                                 "','" + In.Customer.MiddleInitial.GetSqlCompatible(false) + "','" +
                                 In.Customer.LastName.GetSqlCompatible(false) + "','" + In.Customer.Address1.GetSqlCompatible(false) +
                                 "','" + In.Customer.Address2.GetSqlCompatible(false) + "','" +
                                 In.Customer.City.GetSqlCompatible(false) + "','" + In.Customer.State.GetSqlCompatible(false) + "','" +
                                 In.Customer.Zip.GetSqlCompatible(false) + "','" + In.Customer.Country.GetSqlCompatible(false) + "','" +
                                 In.Customer.HomePhone + "'," + In.RegisterId.GetSqlCompatible() + ",'" + In.Customer.Email.GetSqlCompatible(false) + "','" +
                                 In.Customer.ShipName.GetSqlCompatible(false) + "'," + In.Total;
            string winHdrInsertString =
                @"INSERT INTO DBA.WInvHeaders
							(RecordID,
							InvoiceID,
							CustomerID,
							InvDate,
							DateOnly,
							BillCompany,
							BillFName,
							BillMI, 
							BillLName,
							BillAddress,
							BillAddress2,
							BillCity,
							BillState,
							BillZip,
							BillCountry,
							BillPhone,
							RegisterID,
							Email,
							ShipFName,
							InvTotal) 
						VALUES ("                         + winHdrArray + ")";
            bool success = SharedDb.PosimDb.Execute(winHdrInsertString) > 0;
        }
Esempio n. 2
0
        public override void Execute()
        {
            //using (var t = new TransactionScope())
            {
                //Get working invoice Id
                var winvTask = new SaveWorkingInvoiceTask
                {
                    Date = Date,
                    In   = In,
                };
                winvTask.Execute();
                var    wId     = In.Id;
                string invDate = Date.ToString("yyyy'-'MM'-'dd HH':'mm':'ss");

                if (string.IsNullOrEmpty(In.Id))
                {
                    var invTask = new GetInvoiceIdTask
                    {
                        RegisterId    = In.RegisterId,
                        InvoiceStatus = InvoiceStatus.Posted,
                    };
                    invTask.Execute();
                    PostedInvoiceId = invTask.Out;
                }
                else
                {
                    PostedInvoiceId = In.Id;
                }
                //Update Rewards
                var acctPayment = In.Payments.FirstOrDefault(x => x.PaymentType.Id == "Acct" && x.Amount != 0);
                if (acctPayment != null)
                {
                    //insert AR Items
                    string insertArQuery =
                        string.Format(
                            @"INSERT INTO DBA.ARItems(LockFlag,PARENTRECORDID,CLOSEDON,DOCDATE, DOCTYPE,REFNO,TERMS,SALE,PAYMENT,APPLIED,BALANCE,BALANCEFORWARDED,PERIOD,REGISTERID,LATEFEECODE)
						VALUES (0,{0},'2300/jan/01 00:00',{1},0,{2},'Net30',{3},0,0,{3},0,0,{4},0)"                        , In.Customer.RecordID,
                            invDate.GetSqlCompatible(), PostedInvoiceId.GetSqlCompatible(), acctPayment.Amount, In.RegisterId.GetSqlCompatible());
                    SharedDb.PosimDb.Execute(insertArQuery);

                    SharedDb.PosimDb.Execute(string.Format("call ApplyToOldestAux({0})", In.Customer.RecordID));
                }

                //Create posted invoice
                string copyQuery = string.Format("CALL CopyWInv2PInv ('{0}','{1}', '{2}' )", wId, PostedInvoiceId, invDate);
                SharedDb.PosimDb.Execute(copyQuery);

                //Save sharge and signature
                if (In.ChargeDetail != null)
                {
                    In.ChargeDetail.InvoiceId = PostedInvoiceId;
                    new SaveChargeTask {
                        Charge = In.ChargeDetail
                    }.Execute();
                }

                //
                //Post
                string precQuery = "select RecordID from PInvHeaders where InvoiceID = " + PostedInvoiceId.GetSqlCompatible(true);
                var    recordId  = SharedDb.PosimDb.GetInt(precQuery);

                string postQuery = string.Format("CALL PostPInvLines ({0},{1},{2},0,{3},'')", recordId, PostedInvoiceId.GetSqlCompatible(true),
                                                 In.Customer.CustomerID.GetSqlCompatible(true),
                                                 invDate.GetSqlCompatible(true));
                SharedDb.PosimDb.Execute(postQuery);

                if (SendEmailTask.IsValidEmail(In.Customer.Email))
                {
                    Task.Factory.StartNew(() => new SendEmailTask
                    {
                        Invoice = In,
                    }.Execute());
                }
                else
                {
                    Task.Factory.StartNew(() => new ReceiptPrinter().printReceipt(In));
                }

                //Cleanup
                SharedDb.PosimDb.Execute(string.Format("CALL DisposeWInv ({0})", wId.GetSqlCompatible(true)));

                //t.Complete();
                Out = true;
            }
        }