示例#1
0
        protected virtual bool SaveDocument(FinalizeAction action = FinalizeAction.CommitDocument)
        {
            if (sale != null && chkPrintCashReceipt.Active)
            {
                action |= FinalizeAction.PrintCashReceipt | FinalizeAction.CollectSaleData;

                if (sale.IsVATExempt || (sale.VAT.IsZero() && sale.Total > 0))
                {
                    if (VATGroup.GetExemptGroup() == null)
                    {
                        MessageError.ShowDialog(string.Format(Translator.GetString("To print a receipt for a document without VAT you need to define a 0% VAT group in {0} and in the receipt printer if necessary!"), DataHelper.ProductName));
                        return(false);
                    }
                }
            }

            HardwareErrorResponse res;

            do
            {
                res.Retry = false;
                try {
                    BusinessDomain.DeviceManager.FinalizeOperation(new FinalizeOperationOptions {
                        Sale = sale, Document = document, Action = action
                    });
                } catch (InvoiceNumberInUseException ex) {
                    txtNumber.SelectRegion(0, txtNumber.Text.Length);
                    MessageError.ShowDialog(
                        Translator.GetString("The entered document number already exists!"),
                        ErrorSeverity.Error, ex);
                    return(false);
                } catch (HardwareErrorException ex) {
                    res = FormHelper.HandleHardwareError(ex);
                    if (!res.Retry)
                    {
                        dlgEditNewDocument.Respond(ResponseType.Cancel);
                        return(false);
                    }
                } catch (InsufficientItemAvailabilityException ex) {
                    MessageError.ShowDialog(
                        string.Format(Translator.GetString("The document cannot be saved due to insufficient quantities of item \"{0}\"."), ex.ItemName),
                        ErrorSeverity.Warning, ex);
                    dlgEditNewDocument.Respond(ResponseType.Cancel);
                    return(false);
                } catch (Exception ex) {
                    MessageError.ShowDialog(
                        Translator.GetString("An error occurred while saving the document!"),
                        ErrorSeverity.Error, ex);
                    dlgEditNewDocument.Respond(ResponseType.Cancel);
                    return(false);
                }
            } while (res.Retry);

            if (sale != null)
            {
                document.Signature = sale.Signature;
            }

            return(true);
        }
示例#2
0
        protected virtual void InitializeEntries()
        {
            if (vatGroup == null)
            {
                vatGroup = new VATGroup();
            }
            else
            {
                txtName.Text  = vatGroup.Name;
                txtValue.Text = Percent.ToEditString(vatGroup.VatValue);
            }

            cboCode.Load(VATGroup.AllCodes, "Key", "Value", vatGroup.Code);
        }
示例#3
0
        public EditNewVATGroup(VATGroup vatGroup)
        {
            this.vatGroup = vatGroup;

            Initialize();
        }
示例#4
0
        private void InitializeEntries()
        {
            LazyListModel <MesUnit> units = MesUnit.GetAll();

            if (item == null)
            {
                item = new Item();

                if (defaultGroupId.HasValue)
                {
                    gEditPanel.SelectGroupId((int)defaultGroupId);
                }

                if (BusinessDomain.AppConfiguration.AutoGenerateItemCodes)
                {
                    item.AutoGenerateCode();
                }
            }
            else
            {
                gEditPanel.SelectGroupId(item.GroupId);
            }

            txtCode.Text               = item.Code;
            txtName.Text               = item.Name;
            txtDisplayName.Text        = item.Name2;
            txtCatalogNumber1.Text     = item.Catalog;
            txtCatalogNumber2.Text     = item.Catalog2;
            txtCatalogNumber3.Text     = item.Catalog3;
            txvDescription.Buffer.Text = item.Description;

            txtBarCode1.Text = item.BarCode;
            txtBarCode2.Text = item.BarCode2;

            barcodes.Clear();
            if (!string.IsNullOrWhiteSpace(item.BarCode3))
            {
                foreach (string barcode in item.BarCode3.Split(new [] { ',' }, StringSplitOptions.RemoveEmptyEntries))
                {
                    barcodes.Add(barcode);
                }
            }

            if (barcodes.Count == 0)
            {
                barcodes.Add(string.Empty);
            }

            List <KeyValuePair <object, string> > barCodeTypes = Enum.GetValues(typeof(GeneratedBarcodeType))
                                                                 .Cast <object> ()
                                                                 .Select(value => new KeyValuePair <object, string> (value, value.ToString()))
                                                                 .OrderBy(p => p.Value).ToList();

            cboBarcodeType.Load(barCodeTypes, "Key", "Value", BusinessDomain.AppConfiguration.CustomGeneratedBarcodeType);
            txtBarcodeFormat.Text = BusinessDomain.AppConfiguration.CustomGeneratedBarcodeFormat;

            List <MesUnit> validUnits = units.Where(u => !string.IsNullOrWhiteSpace(u.Name)).ToList();

            cbeMesUnit.Load(validUnits, "Name", "Name");
            if (!string.IsNullOrWhiteSpace(item.MUnit))
            {
                cbeMesUnit.Entry.Text = item.MUnit;
            }
            txtMesRatio.Text = Number.ToEditString(item.MUnitRatio);
            cbeMesUnit2.Load(validUnits, "Name", "Name");
            if (!string.IsNullOrWhiteSpace(item.MUnit))
            {
                cbeMesUnit2.Entry.Text = item.MUnit2;
            }
            txtMinimalQty.Text = Quantity.ToEditString(item.MinimalQuantity);
            txtNominalQty.Text = Quantity.ToEditString(item.NominalQuantity);

            LazyListModel <VATGroup>            allGroups = VATGroup.GetAll();
            List <KeyValuePair <long, string> > vatList   = new List <KeyValuePair <long, string> > (allGroups
                                                                                                     .Select(vatGroup => new KeyValuePair <long, string> (vatGroup.Id,
                                                                                                                                                          string.Format("{0} ({1})", vatGroup.Name, Percent.ToString(vatGroup.VatValue)))));

            cboVATGroup.Load(vatList, "Key", "Value", item.VatGroupId);

            SetPrices(item);
        }
        public static void OpenEntityForEdit(SourceItemId entity)
        {
            object id;
            long   intId;
            object type;

            switch (entity.Table)
            {
            case DbTable.Unknown:
                break;

            case DbTable.ApplicationLog:
                break;

            case DbTable.Cashbook:
                break;

            case DbTable.Configuration:
                break;

            case DbTable.Currencies:
                break;

            case DbTable.CurrenciesHistory:
                break;

            case DbTable.Documents:
                id   = entity [DataField.DocumentOperationNumber];
                type = entity [DataField.DocumentType];
                if (type == null)
                {
                    break;
                }

                try {
                    type  = Enum.ToObject(typeof(OperationType), type);
                    intId = Convert.ToInt64(id);
                } catch (Exception ex) {
                    ErrorHandling.LogException(ex);
                    break;
                }

                FormHelper.EditOperation((OperationType)type, intId);
                break;

            case DbTable.EcrReceipts:
                break;

            case DbTable.Items:
                id = entity [DataField.ItemId];
                try {
                    intId = Convert.ToInt64(id);
                } catch (Exception ex) {
                    ErrorHandling.LogException(ex);
                    break;
                }

                if (BusinessDomain.RestrictionTree.GetRestriction("mnuEditGoodsbtnEdit") != UserRestrictionState.Allowed)
                {
                    break;
                }

                using (EditNewItem dialog = new EditNewItem(Item.GetById(intId)))
                    if (dialog.Run() == ResponseType.Ok)
                    {
                        using (new DbMasterScope(BusinessDomain.DataAccessProvider))
                            dialog.GetItem().CommitChanges();
                    }
                break;

            case DbTable.ItemsGroups:
                id = entity [DataField.ItemGroupId];
                try {
                    intId = Convert.ToInt64(id);
                } catch (Exception ex) {
                    ErrorHandling.LogException(ex);
                    break;
                }

                if (BusinessDomain.RestrictionTree.GetRestriction("mnuEditGoodsbtnEdit") != UserRestrictionState.Allowed)
                {
                    break;
                }

                using (EditNewGroup <ItemsGroup> dialog = new EditNewGroup <ItemsGroup> (ItemsGroup.GetById(intId), ItemsGroup.GetAll()))
                    if (dialog.Run() == ResponseType.Ok)
                    {
                        using (new DbMasterScope(BusinessDomain.DataAccessProvider))
                            dialog.GetGroup().CommitChanges();
                    }
                break;

            case DbTable.InternalLog:
                break;

            case DbTable.Lots:
                break;

            case DbTable.Network:
                break;

            case DbTable.NextAcct:
                break;

            case DbTable.Objects:
                id = entity [DataField.LocationId];
                try {
                    intId = Convert.ToInt64(id);
                } catch (Exception ex) {
                    ErrorHandling.LogException(ex);
                    break;
                }

                if (BusinessDomain.RestrictionTree.GetRestriction("mnuEditObjectsbtnEdit") != UserRestrictionState.Allowed)
                {
                    break;
                }

                using (EditNewLocation dialog = new EditNewLocation(Location.GetById(intId)))
                    if (dialog.Run() == ResponseType.Ok)
                    {
                        using (new DbMasterScope(BusinessDomain.DataAccessProvider))
                            dialog.GetLocation().CommitChanges();
                    }
                break;

            case DbTable.ObjectsGroups:
                id = entity [DataField.LocationsGroupsId];
                try {
                    intId = Convert.ToInt64(id);
                } catch (Exception ex) {
                    ErrorHandling.LogException(ex);
                    break;
                }

                if (BusinessDomain.RestrictionTree.GetRestriction("mnuEditObjectsbtnEdit") != UserRestrictionState.Allowed)
                {
                    break;
                }

                using (EditNewGroup <LocationsGroup> dialog = new EditNewGroup <LocationsGroup> (LocationsGroup.GetById(intId), LocationsGroup.GetAll()))
                    if (dialog.Run() == ResponseType.Ok)
                    {
                        using (new DbMasterScope(BusinessDomain.DataAccessProvider))
                            dialog.GetGroup().CommitChanges();
                    }
                break;

            case DbTable.Operations:
                type = entity [DataField.OperationType];
                if (type == null)
                {
                    break;
                }

                id = entity [DataField.OperationNumber];
                try {
                    type  = Enum.ToObject(typeof(OperationType), type);
                    intId = Convert.ToInt64(id);
                } catch (Exception ex) {
                    ErrorHandling.LogException(ex);
                    break;
                }

                FormHelper.EditOperation((OperationType)type, intId);
                break;

            case DbTable.OperationDetails:
                break;

            case DbTable.OperationType:
                break;

            case DbTable.Partners:
                id = entity [DataField.PartnerId];
                try {
                    intId = Convert.ToInt64(id);
                } catch (Exception ex) {
                    ErrorHandling.LogException(ex);
                    break;
                }

                if (BusinessDomain.RestrictionTree.GetRestriction("mnuEditPartnersbtnEdit") != UserRestrictionState.Allowed)
                {
                    break;
                }

                using (EditNewPartner dialog = new EditNewPartner(Partner.GetById(intId)))
                    if (dialog.Run() == ResponseType.Ok)
                    {
                        using (new DbMasterScope(BusinessDomain.DataAccessProvider))
                            dialog.GetPartner().CommitChanges();
                    }
                break;

            case DbTable.PartnersGroups:
                id = entity [DataField.PartnersGroupsId];
                try {
                    intId = Convert.ToInt64(id);
                } catch (Exception ex) {
                    ErrorHandling.LogException(ex);
                    break;
                }

                if (BusinessDomain.RestrictionTree.GetRestriction("mnuEditPartnersbtnEdit") != UserRestrictionState.Allowed)
                {
                    break;
                }

                using (EditNewGroup <PartnersGroup> dialog = new EditNewGroup <PartnersGroup> (PartnersGroup.GetById(intId), PartnersGroup.GetAll()))
                    if (dialog.Run() == ResponseType.Ok)
                    {
                        using (new DbMasterScope(BusinessDomain.DataAccessProvider))
                            dialog.GetGroup().CommitChanges();
                    }
                break;

            case DbTable.Payments:
                type = entity [DataField.PaymentOperationType];
                if (type == null)
                {
                    break;
                }

                id = entity [DataField.PaymentOperationId];
                try {
                    type  = Enum.ToObject(typeof(OperationType), type);
                    intId = Convert.ToInt64(id);
                } catch (Exception ex) {
                    ErrorHandling.LogException(ex);
                    break;
                }

                if (BusinessDomain.RestrictionTree.GetRestriction("mnuEditPaysPaymentsbtnEdit") != UserRestrictionState.Allowed)
                {
                    break;
                }

                Operation oper = Operation.GetById((OperationType)type, intId);
                if (oper == null)
                {
                    break;
                }

                using (EditNewPayment dialog = new EditNewPayment(oper))
                    if (dialog.Run() == ResponseType.Ok)
                    {
                        using (new DbMasterScope(BusinessDomain.DataAccessProvider))
                            oper.CommitPayments();
                    }
                break;

            case DbTable.PaymentTypes:
                id = entity [DataField.PaymentTypesId];
                try {
                    intId = Convert.ToInt64(id);
                } catch (Exception ex) {
                    ErrorHandling.LogException(ex);
                    break;
                }

                using (EditNewPaymentType dialog = new EditNewPaymentType(PaymentType.GetById(intId)))
                    if (dialog.Run() == ResponseType.Ok)
                    {
                        using (new DbMasterScope(BusinessDomain.DataAccessProvider))
                            dialog.GetPaymentType().CommitChanges();
                    }
                break;

            case DbTable.PriceRules:
                break;

            case DbTable.Registration:
                break;

            case DbTable.Store:
                break;

            case DbTable.System:
                break;

            case DbTable.Transformations:
                break;

            case DbTable.Users:
                EditUser(entity [DataField.UserId]);
                break;

            case DbTable.OperationUsers:
                EditUser(entity [DataField.OperationsUserId]);
                break;

            case DbTable.OperationOperators:
                EditUser(entity [DataField.OperationsOperatorId]);
                break;

            case DbTable.UsersGroup:
                EditUserGroup(entity [DataField.UsersGroupsId]);
                break;

            case DbTable.OperationUsersGroup:
                EditUserGroup(entity [DataField.OperationsUsersGroupsId]);
                break;

            case DbTable.OperationOperatorsGroup:
                EditUserGroup(entity [DataField.OperationsOperatorsGroupsId]);
                break;

            case DbTable.UsersSecurity:
                break;

            case DbTable.VatGroups:
                id = entity [DataField.VATGroupId];
                try {
                    intId = Convert.ToInt64(id);
                } catch (Exception ex) {
                    ErrorHandling.LogException(ex);
                    break;
                }

                if (BusinessDomain.RestrictionTree.GetRestriction("mnuEditVATGroupsbtnEdit") != UserRestrictionState.Allowed)
                {
                    return;
                }

                using (EditNewVATGroup dialog = new EditNewVATGroup(VATGroup.GetById(intId)))
                    if (dialog.Run() == ResponseType.Ok)
                    {
                        using (new DbMasterScope(BusinessDomain.DataAccessProvider))
                            dialog.GetVATGroup().CommitChanges();
                    }
                break;
            }
        }
示例#6
0
        protected override void CreateBody()
        {
            CreateBody(Translator.GetString("How do you want to handle the taxes?"));

            #region VAT or Sales tax

            WrapLabel lblVATorTax = new WrapLabel
            {
                Markup = new PangoStyle
                {
                    Size = PangoStyle.TextSize.Large,
                    Text = Translator.GetString("Are you using VAT or Sales tax?")
                }
            };
            lblVATorTax.Show();
            vboBody.PackStart(lblVATorTax, true, true, 5);

            rbnVAT          = new RadioButton(Translator.GetString("VAT"));
            rbnSalesTax     = new RadioButton(rbnVAT, Translator.GetString("Sales tax"));
            rbnVAT.Toggled += rbnVAT_Toggled;

            HBox hbo = new HBox {
                Spacing = 10
            };
            hbo.PackStart(rbnVAT, false, true, 0);
            hbo.PackStart(rbnSalesTax, false, true, 0);
            hbo.ShowAll();
            vboBody.PackStart(hbo, false, true, 5);

            #endregion

            HSeparator hs = new HSeparator();
            hs.Show();
            vboBody.PackStart(hs, true, true, 2);

            #region Default tax

            WrapLabel lblTaxRateTitle = new WrapLabel
            {
                Markup = new PangoStyle
                {
                    Size = PangoStyle.TextSize.Large,
                    Text = Translator.GetString("What is the dafault tax rate you want to use?")
                }
            };
            lblTaxRateTitle.Show();
            vboBody.PackStart(lblTaxRateTitle, true, true, 5);

            Label lblTaxRate = new Label
            {
                Markup = new PangoStyle
                {
                    Text = Translator.GetString("Rate:")
                }
            };

            defaultVatGroup = VATGroup.GetById(VATGroup.DefaultVATGroupId);

            txtTaxRate = new Entry {
                Text = Percent.ToEditString(defaultVatGroup.VatValue)
            };
            txtTaxRate.WidthChars = 10;
            txtTaxRate.Alignment  = 1;

            hbo = new HBox {
                Spacing = 10
            };
            hbo.PackStart(lblTaxRate, false, true, 0);
            hbo.PackStart(txtTaxRate, false, true, 0);
            hbo.ShowAll();
            vboBody.PackStart(hbo, false, true, 5);

            #endregion

            hs = new HSeparator();
            hs.Show();
            vboBody.PackStart(hs, true, true, 2);

            #region With or without VAT

            WrapLabel lblPrices = new WrapLabel
            {
                Markup = new PangoStyle
                {
                    Size = PangoStyle.TextSize.Large,
                    Text = Translator.GetString("How do you want to use the prices in the application? Choose which value you want to round your prices to.")
                }
            };
            lblPrices.Show();
            vboBody.PackStart(lblPrices, true, true, 5);

            rbnWithVAT    = new RadioButton(Translator.GetString("With VAT"));
            rbnWithoutVAT = new RadioButton(rbnWithVAT, Translator.GetString("Without VAT"));

            hbo = new HBox {
                Spacing = 10
            };
            hbo.PackStart(rbnWithVAT, false, true, 0);
            hbo.PackStart(rbnWithoutVAT, false, true, 0);
            hbo.ShowAll();
            vboBody.PackStart(hbo, false, true, 5);

            lblNote = new WrapLabel
            {
                Text = Translator.GetString("Note: You can easely add or subtract VAT after you enter the prices in the operation, using the buttons on the right.")
            };
            lblNote.Show();
            vboBody.PackStart(lblNote, true, true, 5);

            #endregion
        }