private void CheckAndCreateBilling(IClient client) { if (client.IDBilling == null) { client.Billing = _billings.AddNew(item => { item.ID = DbUtils.GenID(); item.Account = item.ID.ToString(); item.Balance = 0; item.Limit = 0; item.OwnerType = BillingLogType.Client; }); } }
void _orders_StatePropertyChanged(object sender, CxPropertyChangedEventArgs <IOrder> e) { PluginParams param; lock (_paramLock) { param = new PluginParams(_param); } var order = e.Object; if (order.State == Enums.OrderStates.Paid && //Заказ оплачен param.IdsServices.Contains(order.IDService ?? 0) && //с указанной услугой order.Cost.HasValue && order.Cost.Value > 0.0 && //и не нулевой стоимостью order.Client != null) { var client = order.Client; if (client.IDBilling == null) //Если у клиента еще нет счета, то создаем его { client.Billing = _billings.AddNew(item => { item.ID = DbUtils.GenID(); item.Account = item.ID.ToString(); item.Balance = 0; item.Limit = 0; item.OwnerType = BillingLogType.Client; }); } var bountySumm = order.Cost.Value * param.Procent; double oldBalance = client.Billing.Balance ?? 0; client.Billing.Balance = oldBalance + bountySumm; //Пополняем счет клиента PaymentRoutine.PaymentRoutine.AddBillingLogsInThreadPool( //И записываем в лог bountySumm, BillingTypes.Order, client.Billing.ID, order.ID, string.Empty, param.BountyDescription, client.Billing.Balance ?? 0, BillingLogType.Client, order.Number); string number = ClientManager.ClientManager.GetManager().GetDefaultPhone(client.ID); string message = string.Format(param.MessageTemplate, bountySumm); if (!string.IsNullOrWhiteSpace(number)) { if (param.NeedMakeCall) { CallManagementInterface.StartAutoinformator(number, message, order.ID); } if (param.NeedSendSMS) { CallManagementInterface.SendSMS(number, message, order.ID); } } else { GlobalLogManager.WriteString("Warning: ClientsBountyManager. У клиента не указан номер телефона"); } } }