public async Task <bool> SendClientBilling(Client client, ClientBilling clientBilling) { string subject = String.Format("{0} - {1}", _boxSettings.APPLICATION_NAME, "Faturamento"); string dataVencimento = clientBilling.PaymentDueDate?.ToString("dd/MM/yyyy"); // create the template dynamic data = _templateService.CreateBasicModel(); data.subject = subject; data.paymentDueDate = dataVencimento; var body = await _templateService.RenderTemplate("ClientBilling", data, lang : "pt"); try { await _emailSender.SendEmailAsync( client.Email, subject, body); _log.Log($"E-mail enviado para o cliente {client.Email} com faturamento que vence em {dataVencimento}.", saveParameters: false); return(true); } catch (Exception ex) { _log.Log($"Erro no envio do faturamento do cliente {client.Name} com vencimento em {dataVencimento}.", ex.Message, saveParameters: false); return(false); } }
public ClientBilling CreateBilling(Client client) { var clientBilling = new ClientBilling() { ClientBillingUId = Guid.NewGuid().ToString(), ClientUId = client.ClientUId, Create = DateTime.Now, PaymentDueDate = Convert.ToDateTime($"{client.DueDay}-{DateTime.Now.Month}-{DateTime.Now.Year}"), PaymentDate = null, Sended = false }; // criar o faturamento na gerencia-net GerenciaNetViewModels.ChargeResponse chargeResponse = CreateBillet(client, clientBilling); // verificar se sucesso, pode gravar o billing if (chargeResponse.code.Equals(200)) { clientBilling.ExternalId = chargeResponse.data.charge_id; clientBilling.BarCode = chargeResponse.data.barcode; clientBilling.LinkPdf = chargeResponse.data.pdf.charge; clientBilling.Status = chargeResponse.data.status; clientBilling.Sended = true; _context.ClientsBillings.Add(clientBilling); _context.SaveChanges(); _log.Log($"Faturamento do cliente {client.Name} com vencimento em {clientBilling.PaymentDueDate.Value.ToShortDateString()} foi criando."); return(clientBilling); } return(null); }
public void addClientBilling() { ClientBilling _clientBilling = new ClientBilling { ClientBillingRateTypeID = 1, ClientID = 27, ClientIsPrivateLabel = false, ClientInvoiceNumber = "JSYTG643T764", ClientAttentionToID = 1, ClientAttentionToFreeText = null }; var _id = _clientRepository.addClientBilling(_clientBilling); Assert.IsTrue(_id > 0, "failed"); }
public void updateClientBilling() { ClientBilling _clientBilling = new ClientBilling { ClientBillingRateTypeID = 1, ClientID = 43, ClientIsPrivateLabel = true, ClientBillingID = 17, ClientInvoiceNumber = "KYU45UN4ER54", ClientAttentionToID = 3, ClientAttentionToFreeText = "ji jvdjd db dfb jdb jdbjhf jhbj jdbvj dfvjd jd jfhdv jdffjdv fjdvb jdfvbfjdvb jfbhv jhdbv jhfbv jdfbv hbfvd fjbvf vdjfk vbdjfvb dkfjvbjdf vfjdbv jbvjd fvbj dfhb" }; var _id = _clientRepository.updateClientBilling(_clientBilling); Assert.IsTrue(_id > 0, "failed"); }
private static StringBuilder GenerateHtmlBilling(ClientBilling clientBilling) { string _htmlTemplateHeader = @" <!DOCTYPE html> <html> <head> <style> body { font-family: Arial, Helvetica, sans-serif; font-size: 12px; } table { border-collapse: collapse; width: 100%; } th, td { text-align: center; padding: 4px; } tr:nth-child(even){ background-color: #f2f2f2 } </style> </head> <body> Wykaz rozmów abonenta <B>[CLIENT]</B> <BR> dla numeracji <B>[CLIDS]</B><BR> za okres od <B>[START_DATE]</B> do <B>[END_DATE]</B><BR> Koszt: netto <B>[PRICE_NETTO]</B> zł, vat <B>[PRICE_VAT]</B> zł, brutto <B>[PRICE_GROSS]</B> zł<BR> <P></P> <table> <tr> <th>Lp.</th> <th>Data i godzina</th> <th>Numer docelowy</th> <th>Czas trwania (min:s)</th> <th>Wartość netto (PLN)</th> </tr>"; string _htmlTemplateBody = @" <tr> <td>[NO]</td> <td>[START_DATE]</td> <td>[DESTINATION]</td> <td>[DURATION]</td> <td>[PRICE_NETTO]</td> </tr>"; string _htmlTemplateFooter = @"</table> </body> </html>"; StringBuilder _htmlClientBilling = new StringBuilder(_htmlTemplateHeader); StringBuilder _htmlBillingRecords = new StringBuilder(); double _priceNettoSum = 0; foreach (var(index, billingRecord) in clientBilling.BillingRecords.Enumerate()) { StringBuilder _htmlBillingRecord = new StringBuilder(_htmlTemplateBody); _htmlBillingRecord.Replace("[NO]", (index + 1).ToString()); _htmlBillingRecord.Replace("[START_DATE]", billingRecord.StartDate.ToString()); _htmlBillingRecord.Replace("[DESTINATION]", billingRecord.Destination.ToString()); _htmlBillingRecord.Replace("[DURATION]", billingRecord.Duration.ToMinutesAndSeconds().ToString()); _htmlBillingRecord.Replace("[PRICE_NETTO]", Math.Round(billingRecord.Price, 2).ToString("0.00")); _htmlBillingRecords.Append(_htmlBillingRecord); _priceNettoSum = _priceNettoSum + billingRecord.Price; } string clids = ""; foreach (string clid in Utils.RangifyLiteralValues(clientBilling.Client.LiteralShortClids())) { clids += clid; if (!clid.Equals(Utils.RangifyLiteralValues(clientBilling.Client.LiteralShortClids()).Last())) { clids += ", "; } } _htmlClientBilling.Replace("[CLIENT]", clientBilling.Client.Name); _htmlClientBilling.Replace("[CLIDS]", clids); _htmlClientBilling.Replace("[START_DATE]", clientBilling.StartDate.ToString()); _htmlClientBilling.Replace("[END_DATE]", clientBilling.EndDate.ToString()); _htmlClientBilling.Replace("[PRICE_NETTO]", Math.Round(_priceNettoSum, 2).ToString("0.00")); _htmlClientBilling.Replace("[PRICE_VAT]", Math.Round(_priceNettoSum * 0.23, 2).ToString("0.00")); _htmlClientBilling.Replace("[PRICE_GROSS]", Math.Round(_priceNettoSum * 1.23, 2).ToString("0.00")); _htmlClientBilling.Append(_htmlBillingRecords); _htmlClientBilling.Append(_htmlTemplateFooter); return(_htmlClientBilling); }
public dynamic CreateBillet(Client client, ClientBilling clientBilling) { _log.Log("Executando método CreateBillet para gerar boleto."); dynamic endpoints = new GerenciaNetEndpoints(_sgiSettings.GERENCIA_NET_CLIENT_ID, _sgiSettings.GERENCIA_NET_CLIENT_SECRET, true); var _value = $"{((int)client.Value).ToString()}00"; dynamic response = null; if (client.DocumentType != (int)DocumentType.CPF) { var body = new { items = new[] { new { name = client.Item, value = Convert.ToInt32(_value), amount = 1 } }, payment = new { banking_billet = new { customer = new { name = client.Name, email = client.Email, cpf = client.Cpf, birth = FormatDate(client.Birth.Value), phone_number = client.Phone, juridical_person = new { corporate_name = client.Name, cnpj = client.Document } }, expire_at = FormatDate(clientBilling.PaymentDueDate.Value) } }, metadata = new { custom_id = clientBilling.ClientBillingUId, notification_url = _sgiSettings.GERENCIA_NET_URL_CALL_BACK } }; response = endpoints.OneStep(null, body); } else { var body = new { items = new[] { new { name = client.Item, value = Convert.ToInt32(_value), amount = 1 } }, payment = new { banking_billet = new { customer = new { name = client.Name, email = client.Email, cpf = client.Cpf, birth = FormatDate(client.Birth.Value), phone_number = client.Phone }, expire_at = FormatDate(clientBilling.PaymentDueDate.Value), } }, metadata = new { custom_id = clientBilling.ClientBillingUId, notification_url = _sgiSettings.GERENCIA_NET_URL_CALL_BACK } }; response = endpoints.OneStep(null, body); } _log.Log("Finalizando método CreateBillet para gerar boleto."); return(JsonConvert.DeserializeObject <ChargeResponse>(response.ToString())); }
public ActionResult AddClientBilling(ClientBilling _ClientBilling, ClientBillingRetailRate _ClientBillingRetailRate, ClientBillingWholesaleRate _ClientBillingWholesaleRate) { try { int _ClientBillingID = 0; string[] _Ids = new string[4]; if (_ClientBilling.ClientBillingID > 0) { _Ids[0] = GlobalConst.Mode.Update; if (_ClientBilling.ClientAttentionToID != 3) { _ClientBilling.ClientAttentionToFreeText = null; } _ClientBillingID = _iClientService.updateClientBilling(Mapper.Map <MMC.MMCService.ClientService.ClientBilling>(_ClientBilling)); _Ids[1] = _ClientBilling.ClientBillingID.ToString();; _ClientBillingRetailRate.ClientBillingID = _ClientBilling.ClientBillingID; _ClientBillingRetailRate.CreatedBy = MMCUser.UserId; _ClientBillingRetailRate.CreatedOn = System.DateTime.Now; _Ids[2] = _ClientBillingRetailRate.ClientBillingRetailRateID.ToString(); _iClientService.updateClientBillingRetailRate(Mapper.Map <MMC.MMCService.ClientService.ClientBillingRetailRate>(_ClientBillingRetailRate)); if (_ClientBilling.ClientIsPrivateLabel == true) { _ClientBillingWholesaleRate.ClientBillingID = _ClientBilling.ClientBillingID; _ClientBillingWholesaleRate.CreatedBy = MMCUser.UserId; _ClientBillingWholesaleRate.CreatedOn = System.DateTime.Now; _Ids[3] = _ClientBillingWholesaleRate.ClientBillingWholesaleRateID.ToString(); _iClientService.updateClientBillingWholesaleRate(Mapper.Map <MMC.MMCService.ClientService.ClientBillingWholesaleRate>(_ClientBillingWholesaleRate)); } else { if (_ClientBillingWholesaleRate.ClientBillingWholesaleRateID > 0) { _iClientService.deleteClientBillingWholesaleRate(_ClientBillingWholesaleRate.ClientBillingWholesaleRateID); } // delete the Client Private Label _iClientService.deleteClientPrivateLabelByClientID(_ClientBilling.ClientID); } } else { _Ids[0] = GlobalConst.Mode.Add; if (_ClientBilling.ClientAttentionToID != 3) { _ClientBilling.ClientAttentionToFreeText = null; } _ClientBilling.ClientBillingID = _iClientService.addClientBilling(Mapper.Map <MMC.MMCService.ClientService.ClientBilling>(_ClientBilling)); _Ids[1] = _ClientBilling.ClientBillingID.ToString(); _ClientBillingRetailRate.ClientBillingID = _ClientBilling.ClientBillingID; _ClientBillingRetailRate.CreatedBy = MMCUser.UserId; _ClientBillingRetailRate.CreatedOn = System.DateTime.Now; _ClientBillingRetailRate.ClientBillingRetailRateID = _iClientService.addClientBillingRetailRate(Mapper.Map <MMC.MMCService.ClientService.ClientBillingRetailRate>(_ClientBillingRetailRate)); _Ids[2] = _ClientBillingRetailRate.ClientBillingRetailRateID.ToString(); if (_ClientBilling.ClientIsPrivateLabel == true) { _ClientBillingWholesaleRate.ClientBillingID = _ClientBilling.ClientBillingID; _ClientBillingWholesaleRate.CreatedBy = MMCUser.UserId; _ClientBillingWholesaleRate.CreatedOn = System.DateTime.Now; _ClientBillingWholesaleRate.ClientBillingWholesaleRateID = _iClientService.addClientBillingWholesaleRate(Mapper.Map <MMC.MMCService.ClientService.ClientBillingWholesaleRate>(_ClientBillingWholesaleRate)); _Ids[3] = _ClientBillingWholesaleRate.ClientBillingWholesaleRateID.ToString(); } } return(Json(_Ids, GlobalConst.ContentTypes.TextHtml)); } catch { return(Json(0)); } }
public int updateClientBilling(ClientBilling _ClientBilling) { return(_clientRepository.updateClientBilling(Mapper.Map <DTO.ClientBilling, MMC.Core.Data.Model.ClientBilling>(_ClientBilling))); }
public int updateClientBilling(ClientBilling _clientBilling) { return(_clientBillingRepo.Update(_clientBilling)); }
public int addClientBilling(ClientBilling _clientBilling) { return(_clientBillingRepo.Add(_clientBilling).ClientBillingID); }