Ejemplo n.º 1
0
 private async Task <string> SaveExchangeItems(string docno, SalesLine record, decimal unitprice)
 {
     try
     {
         DataManager manager = new DataManager();
         SalesLine   line    = new SalesLine()
         {
             ID                    = 0,
             DocumentNo            = docno,
             ItemNo                = record.ItemNo,
             Description           = record.Description,
             UnitofMeasurementCode = record.UnitofMeasurementCode,
             Quantity              = record.Quantity,
             BadQuantity           = record.BadQuantity,
             FOCQty                = 0,
             UnitPrice             = unitprice,
             ItemType              = record.ItemType,
         };
         string retval = manager.SaveSQLite_SalesLine(line);
         return(retval);
     }
     catch (Exception ex)
     {
         return(ex.Message.ToString());
     }
 }
Ejemplo n.º 2
0
        private async void SaveButton_Clicked(object sender, EventArgs e)
        {
            if (_isEnableSaveBtn)
            {
                _isEnableSaveBtn = false;
                if (CurStatus == "Open")
                {
                    if (!string.IsNullOrEmpty(SellToCustomerEntry.Text))
                    {
                        DataManager manager = new DataManager();
                        string      retval  = await manager.SaveSQLite_SalesHeader(new SalesHeader
                        {
                            ID             = EntryNo,
                            DocumentNo     = InvoiceNoLabel.Text,
                            DocumentDate   = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss tt"),//DocumentDatePicker.Date.ToString("yyyy-MM-dd"),
                            SellToCustomer = SellToCustomerEntry.Text,
                            SellToName     = SellToNameLabel.Text,
                            BillToCustomer = BillToCustNo,
                            BillToName     = BilltoName,
                            Status         = "Open",
                            TotalAmount    = SubTotal,
                            GSTAmount      = GSTAmount,
                            NetAmount      = NetTotal,
                            DocumentType   = App.gDocType,
                            Note           = string.Empty,
                            IsVoid         = "false",
                            IsSync         = "false",
                            SyncDateTime   = string.Empty,
                            ExternalDocNo  = ExternalDocNoEntry.Text
                        });

                        if (retval == "Success")
                        {
                            // Edit Sales line if Customer Changed
                            if (!string.IsNullOrEmpty(originCust))
                            {
                                if (originCust != SellToCustomerEntry.Text)
                                {
                                    ObservableCollection <SalesLine> prevLines = new ObservableCollection <SalesLine>();
                                    manager   = new DataManager();
                                    prevLines = manager.GetSalesLinesbyDocNo(InvoiceNoLabel.Text);
                                    if (prevLines != null)
                                    {
                                        if (prevLines.Count > 0)
                                        {
                                            foreach (SalesLine s in prevLines)
                                            {
                                                SalesLine line = new SalesLine()
                                                {
                                                    ID                    = s.ID,
                                                    DocumentNo            = s.DocumentNo,
                                                    ItemNo                = s.ItemNo,
                                                    Description           = s.Description,
                                                    UnitofMeasurementCode = s.UnitofMeasurementCode,
                                                    Quantity              = s.Quantity,
                                                    BadQuantity           = s.BadQuantity,
                                                    FOCQty                = s.FOCQty,
                                                    UnitPrice             = GetDefaultPrice(s.ItemNo),
                                                    GoodReasonCode        = s.GoodReasonCode,
                                                    BadReasonCode         = s.BadReasonCode,
                                                    ItemType              = s.ItemType,
                                                    // BagNo=ScanBagEntry.Text
                                                    //IsSync = "false",
                                                    //SyncDateTime = string.Empty
                                                };
                                                retval = manager.SaveSQLite_SalesLine(line);
                                            }
                                            if (retval == "Success")
                                            {
                                                ObservableCollection <SalesLine> lines = new ObservableCollection <SalesLine>();
                                                lines = manager.GetSalesLinesbyDocNo(InvoiceNoLabel.Text);
                                                decimal new_amt = lines.Sum(x => x.LineAmount);
                                                retval = manager.UpdateSalesHeaderTotalAmount(new_amt, InvoiceNoLabel.Text, lines);
                                            }
                                        } // end check line count
                                    }     // line!=null
                                }
                            }
                            if (EntryNo == 0) //DD #284
                            {
                                if (App.gDocType == "SO")
                                {
                                    manager.IncreaseNoSeries(App.gSOPrefix, InvoiceNoLabel.Text, "SO");
                                }
                                else
                                {
                                    manager.IncreaseNoSeries(App.gCRPrefix, InvoiceNoLabel.Text, "CR");
                                }
                            }

                            UserDialogs.Instance.ShowSuccess(retval, 3000);
                            Navigation.PopAsync();
                        }
                        else
                        {
                            UserDialogs.Instance.ShowError(retval, 3000);
                            _isEnableSaveBtn = true;
                        }
                    }
                    else
                    {
                        UserDialogs.Instance.ShowError("Required Sell to Customer!", 3000);
                        SellToCustomerEntry.Focus();
                        _isEnableSaveBtn = true;
                    }
                }
                else
                {
                    UserDialogs.Instance.ShowError("Not allow to save released Sales Order!", 3000);
                    _isEnableSaveBtn = true;
                }
            }
        }
Ejemplo n.º 3
0
        private async void CopyButton_OnClicked(object sender, EventArgs e)
        {
            if (_isEnableCopyBtn)
            {
                _isEnableCopyBtn = false;
                string msg    = string.Empty;
                string retval = string.Empty;
                isvoid = "true";
                DataManager manager = new DataManager();
                ObservableCollection <SalesLine> recItems = new ObservableCollection <SalesLine>();
                try
                {
                    //if (App.gDocType == "SO")
                    //    msg = "Are you sure to void Sales Order?";
                    //else
                    //    msg = "Are you sure to void Credit Memo?";

                    var answer = await DisplayAlert("Confirm", "Are you sure to copy void Order?", "Yes", "No");

                    Device.BeginInvokeOnMainThread(() => UserDialogs.Instance.ShowLoading("Loading", MaskType.Black));
                    Task.Run(async() =>
                    {
                        if (answer)
                        {
                            recItems = manager.GetSalesLinesbyDocNo(DocumentNo);

                            if (CheckItemBalance(recItems) == true)
                            {
                                manager         = new DataManager();
                                string newDocNo = manager.GetLastNoSeries(App.gSOPrefix);
                                retval          = await manager.SaveSQLite_SalesHeader(new SalesHeader
                                {
                                    ID             = 0,
                                    DocumentNo     = newDocNo,
                                    DocumentDate   = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss tt"),//DocumentDatePicker.Date.ToString("yyyy-MM-dd"),
                                    SellToCustomer = head.SellToCustomer,
                                    SellToName     = head.SellToName,
                                    BillToCustomer = head.BillToCustomer,
                                    BillToName     = head.BillToName,
                                    Status         = "Open",
                                    TotalAmount    = head.TotalAmount,
                                    GSTAmount      = head.GSTAmount,
                                    NetAmount      = head.NetAmount,
                                    DocumentType   = head.DocumentType,
                                    Note           = head.Note,
                                    IsVoid         = "false",
                                    IsSync         = "false",
                                    SyncDateTime   = string.Empty,
                                    ExternalDocNo  = head.ExternalDocNo
                                });
                                if (retval == "Success")
                                {
                                    if (recItems != null)
                                    {
                                        if (recItems.Count > 0)
                                        {
                                            foreach (SalesLine s in recItems)
                                            {
                                                SalesLine line = new SalesLine()
                                                {
                                                    ID                    = 0,
                                                    DocumentNo            = newDocNo,
                                                    ItemNo                = s.ItemNo,
                                                    Description           = s.Description,
                                                    UnitofMeasurementCode = s.UnitofMeasurementCode,
                                                    Quantity              = s.Quantity,
                                                    BadQuantity           = s.BadQuantity,
                                                    FOCQty                = 0,
                                                    UnitPrice             = s.UnitPrice,
                                                    GoodReasonCode        = s.GoodReasonCode,
                                                    BadReasonCode         = s.BadReasonCode,
                                                    ItemType              = s.ItemType,
                                                    BagNo                 = s.BagNo
                                                };
                                                string retline = manager.SaveSQLite_SalesLine(line);
                                                if (retline == "Success")
                                                {
                                                    Item iobj = new Item();
                                                    iobj      = manager.GetSQLite_ItembyItemNo(s.ItemNo);
                                                    //decimal soldQty = 0;
                                                    //if (s.ItemType != "EXC")
                                                    //    soldQty = iobj.SoldQty + s.Quantity;
                                                    //else
                                                    //    soldQty = iobj.SoldQty + s.BadQuantity;
                                                    //manager.UpdateSQLite_SOInventory(s.ItemNo, soldQty);

                                                    if (App.gDocType == "SO")
                                                    {
                                                        decimal soldQty = 0;
                                                        if (s.ItemType == "EXC")
                                                        {
                                                            soldQty           = iobj.SoldQty + s.BadQuantity;
                                                            decimal excBadQty = iobj.BadQty + s.BadQuantity;
                                                            manager.UpdateSQLite_ExchangeInventory(s.ItemNo, excBadQty);
                                                        }
                                                        else
                                                        {
                                                            soldQty = iobj.SoldQty + s.Quantity;
                                                        }

                                                        manager.UpdateSQLite_SOInventory(s.ItemNo, soldQty);
                                                    }
                                                    else
                                                    {
                                                        decimal returnQty = iobj.ReturnQty - s.Quantity;
                                                        decimal badQty    = iobj.BadQty - s.BadQuantity;
                                                        manager.UpdateSQLite_ReturnInventory(s.ItemNo, returnQty, badQty);
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    manager.IncreaseNoSeries(App.gSOPrefix, newDocNo, "SO");
                                }
                            }
                            else
                            {
                                retval = "Not enough quantity!";
                            }
                        }
                    }).ContinueWith(result => Device.BeginInvokeOnMainThread(() =>
                    {
                        UserDialogs.Instance.HideLoading();
                        if (!string.IsNullOrEmpty(retval))
                        {
                            if (retval == "Success")
                            {
                                UserDialogs.Instance.ShowSuccess(retval, 3000);
                                App.gSOStatus = "Open";
                                Navigation.PushAsync(new MainPage(1));
                            }
                            else
                            {
                                UserDialogs.Instance.ShowError(retval, 3000);
                                _isEnableCopyBtn = true;
                            }
                        }
                    }));
                }
                catch (OperationCanceledException ex)
                {
                    Acr.UserDialogs.UserDialogs.Instance.HideLoading(); //IsLoading = false;
                    UserDialogs.Instance.ShowError(ex.Message.ToString(), 3000);
                    _isEnableCopyBtn = true;
                }
                catch (Exception ex)
                {
                    UserDialogs.Instance.HideLoading(); //IsLoading = false;
                    UserDialogs.Instance.ShowError(ex.Message.ToString(), 3000);
                    _isEnableCopyBtn = true;
                }
            }
        }
Ejemplo n.º 4
0
        async Task <string> SyncSalesOrder()
        {
            try
            {
                ObservableCollection <SalesHeader> lsthd = new ObservableCollection <SalesHeader>();
                DataManager manager  = new DataManager();
                string      alertmsg = string.Empty;
                //lsthd = await manager.GetSQLite_SalesHeaderbyStatus("Released", "SO");
                // lsthd = await manager.GetSQLite_SalesHeaderbyStatus("Released", "CN");
                lsthd = await manager.GetSQLite_SalesOrderbyStatus("Released");

                if (lsthd != null && lsthd.Count > 0)
                {
                    foreach (SalesHeader s in lsthd)
                    {
                        string retmsg = App.svcManager.ExportSalesHeader(s.DocumentNo, s.SellToCustomer, s.SellToName, s.BillToCustomer, s.BillToName, s.DocumentDate, s.Status, s.PaymentMethod, s.TotalAmount, s.DocumentType, s.Note, s.StrSignature, App.gSalesPersonCode, App.gDeviceId, s.Comment, s.IsVoid, s.ExternalDocNo);
                        if (retmsg == "Success")
                        {
                            manager = new DataManager();
                            string retval = await manager.SaveSQLite_SalesHeader(new SalesHeader
                            {
                                ID             = s.ID,
                                DocumentNo     = s.DocumentNo,
                                DocumentDate   = s.DocumentDate,
                                BillToCustomer = s.BillToCustomer,
                                BillToName     = s.BillToName,
                                SellToCustomer = s.SellToCustomer,
                                SellToName     = s.SellToName,
                                TotalAmount    = s.TotalAmount,
                                GSTAmount      = s.GSTAmount,
                                NetAmount      = s.NetAmount,
                                Status         = "Released",
                                PaymentMethod  = s.PaymentMethod,
                                StrSignature   = s.StrSignature,
                                DocumentType   = s.DocumentType,
                                Note           = s.Note,
                                Comment        = s.Comment,
                                IsVoid         = s.IsVoid,
                                IsSync         = "true",
                                SyncDateTime   = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss tt"),
                                ExternalDocNo  = s.ExternalDocNo
                            });

                            ObservableCollection <SalesLine> lstline = new ObservableCollection <SalesLine>();
                            lstline = manager.GetSalesLinesbyDocNo(s.DocumentNo);
                            if (lstline != null && lstline.Count > 0)
                            {
                                foreach (SalesLine l in lstline)
                                {
                                    retmsg = App.svcManager.ExportSalesLine(l.ID.ToString(), l.DocumentNo, l.ItemNo, l.LocationCode, l.Quantity, l.FOCQty, l.BadQuantity, l.UnitofMeasurementCode, l.UnitPrice, l.LineDiscountPercent, l.LineDiscountAmount, l.LineAmount, l.GoodReasonCode, l.BadReasonCode, l.ItemType);
                                    if (retmsg == "Success")
                                    {
                                        manager = new DataManager();
                                        SalesLine line = new SalesLine()
                                        {
                                            ID                    = l.ID,
                                            DocumentNo            = l.DocumentNo,
                                            ItemNo                = l.ItemNo,
                                            Description           = l.Description,
                                            UnitofMeasurementCode = l.UnitofMeasurementCode,
                                            Quantity              = l.Quantity,
                                            FOCQty                = l.FOCQty,
                                            UnitPrice             = l.UnitPrice,
                                            //IsSync = "true",
                                            //SyncDateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss tt")
                                        };
                                        retval = manager.SaveSQLite_SalesLine(line);
                                        //alertmsg = "Sales Order sync success!";
                                        alertmsg = "Success";
                                    }
                                    else
                                    {
                                        alertmsg = "Can not able to sync doc no " + l.DocumentNo + " -> Item No" + l.ItemNo + ". Err message: " + retmsg;
                                    }
                                }
                            }
                            else
                            {
                                alertmsg = "No line records";
                                break;
                            }
                            // Sync Num series
                            SyncNumberSeries();
                        }
                        else
                        {
                            alertmsg = "Can not able to sync doc No " + s.DocumentNo + ". Err message: " + retmsg;
                            break;
                        }
                    }
                }
                else
                {
                    alertmsg = "No records";
                }
                return(alertmsg);
            }
            catch (Exception ex)
            {
                UserDialogs.Instance.HideLoading(); //IsLoading = false;
                return(ex.Message.ToString());
            }
        }