public SalesDocumentNode CreateSalesDocument(Order order) { var exportSaleDocument = new SalesDocumentNode { Id = ++objectCounter }; exportSaleDocument.Reference = new ReferenceNode(exportSaleDocument.Id, new PropertyNode("Номер", Common1cTypes.String, ExportMode == Export1cMode.IPForTinkoff ? order.OnlineOrder.Value : order.Id), new PropertyNode("Дата", Common1cTypes.Date, order.DeliveryDate.Value.ToString("s")) ); var exportGoodsTable = new TableNode { Name = "Товары", }; var exportServicesTable = new TableNode { Name = "Услуги", }; foreach (var orderItem in order.OrderItems) { var record = CreateRecord(orderItem); if (Nomenclature.GetCategoriesForGoods().Contains(orderItem.Nomenclature.Category)) { exportGoodsTable.Records.Add(record); exportSaleDocument.Comission.Comissions.Add(0); } else { exportServicesTable.Records.Add(record); } } exportSaleDocument.Properties.Add( new PropertyNode("Организация", Common1cTypes.ReferenceOrganization, OrganizationCatalog.CreateReferenceTo(order.Contract.Organization) ) ); exportSaleDocument.Properties.Add( new PropertyNode("Комментарий", Common1cTypes.String, order.Comment ) ); exportSaleDocument.Properties.Add( new PropertyNode("Склад", Common1cTypes.ReferenceWarehouse, WarehouseCatalog.CreateReferenceTo(Warehouse1c.Default) ) ); exportSaleDocument.Properties.Add( new PropertyNode("Контрагент", Common1cTypes.ReferenceCounterparty, CounterpartyCatalog.CreateReferenceTo(order.Client) ) ); exportSaleDocument.Properties.Add( new PropertyNode("ДоговорКонтрагента", Common1cTypes.ReferenceContract, ContractCatalog.CreateReferenceToContract(order) ) ); exportSaleDocument.Properties.Add( new PropertyNode("ВалютаДокумента", Common1cTypes.ReferenceCurrency, CurrencyCatalog.CreateReferenceTo(OldExportTo1c.Currency.Default) ) ); exportSaleDocument.Properties.Add( new PropertyNode("УчитыватьНДС", Common1cTypes.Boolean, "true" ) ); exportSaleDocument.Properties.Add( new PropertyNode("СуммаВключаетНДС", Common1cTypes.Boolean, "true" ) ); exportSaleDocument.Properties.Add( new PropertyNode("ВидОперации", "ПеречислениеСсылка.ВидыОперацийРеализацияТоваров", "ПродажаКомиссия" ) ); exportSaleDocument.Properties.Add( new PropertyNode("КурсВзаиморасчетов", Common1cTypes.Numeric, 1 ) ); exportSaleDocument.Properties.Add( new PropertyNode("КратностьВзаиморасчетов", Common1cTypes.Numeric, 1 ) ); exportSaleDocument.Tables.Add(exportGoodsTable); exportSaleDocument.Tables.Add(exportServicesTable); return(exportSaleDocument); }
/** * Modelo "Complemento de pago" * - Se especifica: la moneda, método de pago, forma de pago, cliente, y lugar de expedición */ private static Facturama.Models.Request.Cfdi CreateModelCfdiPaymentComplement(FacturamaApi facturama, Facturama.Models.Response.Cfdi cfdiInicial) { Cfdi cfdi = new Cfdi(); // Lista del catálogo de nombres en el PDF var nameForPdf = facturama.Catalogs.NameIds.First(m => m.Value == "14"); // Nombre en el pdf: "Complemento de pago" cfdi.NameId = nameForPdf.Value; // Receptor de comprobante (se toma como cliente el mismo a quien se emitió el CFDI Inicial), String clientRfc = cfdiInicial.Receiver.Rfc; Client client = facturama.Clients.List().Where(p => p.Rfc.Equals(clientRfc)).First(); Receiver receiver = new Receiver { CfdiUse = "P01", Name = client.Name, Rfc = client.Rfc }; cfdi.Receiver = receiver; // Lugar de expedición (es necesario por lo menos tener una sucursal) BranchOffice branchOffice = facturama.BranchOffices.List().First(); cfdi.ExpeditionPlace = "78240"; // Fecha y hora de expecidión del comprobante //DateTime bindingDate; //DateTime.TryParse(cfdiBinding.Date, null, DateTimeStyles.RoundtripKind, out bindingDate); cfdi.Date = null; // Puedes especificar una fecha por ejemplo: DateTime.Now cfdi.CfdiType = CfdiType.Pago; // Complemento de pago --- Complement complement = new Complement(); // Pueden representarse más de un pago en un solo CFDI List <Facturama.Models.Complements.Payment> lstPagos = new List <Facturama.Models.Complements.Payment>(); Facturama.Models.Complements.Payment pago = new Facturama.Models.Complements.Payment(); // Fecha y hora en que se registró el pago en el formato: "yyyy-MM-ddTHH:mm:ss" // (la fecha del pago debe ser menor que la fecha en que se emite el CFDI) // Para este ejemplo, se considera que el pago se realizó hace una hora pago.Date = DateTime.Now.AddHours(-6).ToString("yyyy-MM-dd HH:mm:ss"); // Forma de pago (Efectivo, Tarjeta, etc) Facturama.Models.Response.Catalogs.CatalogViewModel paymentForm = facturama.Catalogs.PaymentForms.Where(p => p.Name.Equals("Efectivo")).First(); pago.PaymentForm = paymentForm.Value; // Selección de la moneda del catálogo // La Moneda, puede ser diferente a la del documento inicial // (En el caso de que sea diferente, se debe colocar el tipo de cambio) List <CurrencyCatalog> lstCurrencies = facturama.Catalogs.Currencies.ToList(); CurrencyCatalog currency = lstCurrencies.Where(p => p.Value.Equals("MXN")).First(); pago.Currency = currency.Value; // Monto del pago // Este monto se puede distribuir entre los documentos relacionados al pago pago.Amount = 100.00m; // Documentos relacionados con el pago // En este ejemplo, los datos se obtiene el cfdiInicial, pero puedes colocar solo los datos // aun sin tener el "Objeto" del cfdi Inicial, ya que los valores son del tipo "String" List <Facturama.Models.Complements.RelatedDocument> lstRelatedDocuments = new List <Facturama.Models.Complements.RelatedDocument>(); Facturama.Models.Complements.RelatedDocument relatedDocument = new Facturama.Models.Complements.RelatedDocument { Uuid = cfdiInicial.Complement.TaxStamp.Uuid, // "27568D31-E579-442F-BA77-798CBF30BD7D" Serie = "A", //cfdiInicial.Serie, // "EA" Folio = cfdiInicial.Folio, // 34853 Currency = currency.Value, PaymentMethod = "PUE", // En el complemento de pago tiene que ser PUE PartialityNumber = 1, PreviousBalanceAmount = 100.00m, AmountPaid = 100.00m }; lstRelatedDocuments.Add(relatedDocument); pago.RelatedDocuments = lstRelatedDocuments; lstPagos.Add(pago); complement.Payments = lstPagos; cfdi.Complement = complement; return(cfdi); }
public void AddOrder(Order order) { OrdersTotalSum += order.TotalSum; var exportSalesDocument = CreateSalesDocument(order); var exportInvoiceDocument = new InvoiceDocumentNode { Id = ++objectCounter }; exportInvoiceDocument.Reference = new ReferenceNode(exportInvoiceDocument.Id, new PropertyNode("Номер", Common1cTypes.String, ExportMode == Export1cMode.IPForTinkoff ? order.OnlineOrder.Value : order.Id), new PropertyNode("Дата", Common1cTypes.Date, order.DeliveryDate.Value.ToString("s")) ); exportInvoiceDocument.Properties.Add( new PropertyNode("Организация", Common1cTypes.ReferenceOrganization, OrganizationCatalog.CreateReferenceTo(order.Contract.Organization) ) ); exportInvoiceDocument.Properties.Add( new PropertyNode("Комментарий", Common1cTypes.String ) ); exportInvoiceDocument.Properties.Add( new PropertyNode("ДоговорКонтрагента", Common1cTypes.ReferenceContract, ContractCatalog.CreateReferenceToContract(order) ) ); exportInvoiceDocument.Properties.Add( new PropertyNode("ДокументОснование", "ДокументСсылка.РеализацияТоваровУслуг", exportSalesDocument.Reference ) ); exportInvoiceDocument.Properties.Add( new PropertyNode("ВидСчетаФактуры", Common1cTypes.EnumInvoiceType, "НаРеализацию" ) ); exportInvoiceDocument.Properties.Add( new PropertyNode("НомерПлатежноРасчетногоДокумента", Common1cTypes.String ) ); exportInvoiceDocument.Properties.Add( new PropertyNode("ДатаПлатежноРасчетногоДокумента", Common1cTypes.Date ) ); exportInvoiceDocument.Properties.Add( new PropertyNode("ВалютаДокумента", Common1cTypes.ReferenceCurrency, CurrencyCatalog.CreateReferenceTo(Currency.Default) ) ); exportInvoiceDocument.Properties.Add( new PropertyNode("СтавкаНДС", Common1cTypes.EnumVAT ) ); exportInvoiceDocument.Properties.Add( new PropertyNode("Сумма", Common1cTypes.Numeric ) ); exportInvoiceDocument.Properties.Add( new PropertyNode("СуммаНДС", Common1cTypes.Numeric ) ); exportInvoiceDocument.Properties.Add( new PropertyNode("Контрагент", Common1cTypes.ReferenceCounterparty, CounterpartyCatalog.CreateReferenceTo(order.Client) ) ); exportInvoiceDocument.Properties.Add( new PropertyNode("ПометкаУдаления", Common1cTypes.Boolean ) ); exportInvoiceDocument.Properties.Add( new PropertyNode("Проведен", Common1cTypes.Boolean, "true" ) ); Objects.Add(exportSalesDocument); Objects.Add(exportInvoiceDocument); }
public void CreateRetailDocument(Order order) { if (!order.DeliveryDate.HasValue) { throw new ArgumentNullException(nameof(order.DeliveryDate)); } if (!RetailDocumentsList.TryGetValue(order.DeliveryDate.Value.Date, out RetailDocumentNode exportRetailDocument)) { exportRetailDocument = new RetailDocumentNode { Id = ++objectCounter }; exportRetailDocument.Reference = new ReferenceNode( exportRetailDocument.Id, new PropertyNode( "Номер", Common1cTypes.String, ExportMode == Export1cMode.IPForTinkoff ? (order.OnlineOrder ?? throw new ArgumentNullException(nameof(order.OnlineOrder), $@"(OrderId: {order.Id})")) : order.Id), new PropertyNode( "Дата", Common1cTypes.Date, order.DeliveryDate.Value.Date.ToString("s")) ); var exportGoodsTable = new TableNode { Name = "Товары", }; var exportRefundGoodsTable = new TableNode { Name = "Возвраты", }; var exportTerminalTable = new TableNode { Name = "Оплата", }; var exportRefundTerminalTable = new TableNode { Name = "ВозвратОплаты", }; exportRetailDocument.Properties.Add( new PropertyNode("Организация", Common1cTypes.ReferenceOrganization, OrganizationCatalog.CreateReferenceTo(order.Contract.Organization)) ); exportRetailDocument.Properties.Add( new PropertyNode("Комментарий", Common1cTypes.String, order.Comment ) ); exportRetailDocument.Properties.Add( new PropertyNode("Склад", Common1cTypes.ReferenceWarehouse, WarehouseCatalog.CreateReferenceTo(Warehouse1c.Default) ) ); exportRetailDocument.Properties.Add( new PropertyNode("ВалютаДокумента", Common1cTypes.ReferenceCurrency, CurrencyCatalog.CreateReferenceTo(ExportTo1c.Currency.Default) ) ); exportRetailDocument.Properties.Add( new PropertyNode("СуммаВключаетНДС", Common1cTypes.Boolean, "true" ) ); exportRetailDocument.Properties.Add( new PropertyNode("ВидОперации", "ПеречислениеСсылка.ВидыОперацийОтчетОРозничныхПродажах", "ОтчетККМОПродажах" ) ); exportRetailDocument.Tables.Add(exportGoodsTable); exportRetailDocument.Tables.Add(exportTerminalTable); exportRetailDocument.Tables.Add(exportRefundGoodsTable); exportRetailDocument.Tables.Add(exportRefundTerminalTable); } bool isTerminalPaid = (order.PaymentType == PaymentType.ByCard || order.PaymentType == PaymentType.Terminal); bool isRefund = false; foreach (var orderItem in order.OrderItems) { isRefund = (orderItem.ActualSum < 0); if (orderItem.ActualSum != 0) { var record = CreateRetailRecord(orderItem); exportRetailDocument.Tables[0].Records.Add(record); //Товары if (isRefund) { exportRetailDocument.Tables[2].Records.Add(record); } if (isTerminalPaid) { var recordPayment = new TableRecordNode(); recordPayment.Properties.Add( new PropertyNode("СуммаОплаты", Common1cTypes.Numeric, orderItem.ActualSum ) ); //оплаты безналом exportRetailDocument.Tables[1].Records.Add(recordPayment); if (isRefund) { exportRetailDocument.Tables[3].Records.Add(recordPayment); } } } } if (!RetailDocumentsList.ContainsKey(order.DeliveryDate.Value.Date)) { RetailDocumentsList.Add(order.DeliveryDate.Value.Date, exportRetailDocument); } }