stark писал(а):
А расход и приход как считаются ? Я к тому что вроде как это должно итак все автоматом считаться (и расходы и платежи и наработка и баланс ).
Вот так, если б все автоматом считалось, яп не поднимал тему

Если не использовать калькулятор, переносится не корректная сумма.
Код:
ContractBalance balance = balanceService.contractBalanceGet(cid1, calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH)+1);
Charge charge = new Charge(0, uid, cid1, chargeId, calendar.getTime(), "Перенос средств на договор №" + cm.getContractById(cid2).getTitle(), balance.toBalance(), calendar.getTime());
chargeService.chargeUpdate(charge);
Payment payment = new Payment(0, uid, cid2, paymentId, calendar.getTime(), "Перенесено с договора №" + cm.getContractById(cid1).getTitle(), balance.toBalance(), calendar.getTime());
paymentService.paymentUpdate(payment, null);
где cid1 - старый договор, cid2 - новый.
Код:
package ru.borin.action;
import ru.bitel.bgbilling.common.BGException;
import ru.bitel.common.XMLUtils;
import java.sql.SQLException;
public class ActionWrapContract extends bitel.billing.server.contract.action.ActionWrapContract {
public void doAction() throws SQLException, BGException {
super.doAction();
int uid = this.userID;
int oldCid = this.cid;
int newCid = Integer.valueOf(XMLUtils.selectText(rootNode, "contract/@id"));
ActionUtils actionUtils = new ActionUtils(this.setup, this.con);
actionUtils.moveBalance(oldCid, newCid, uid);
}
}
Код:
package ru.borin.action;
import bitel.billing.server.contract.bean.ContractManager;
import ru.bitel.bgbilling.common.BGException;
import ru.bitel.bgbilling.common.BGMessageException;
import ru.bitel.bgbilling.kernel.container.managed.ServerContext;
import ru.bitel.bgbilling.kernel.contract.balance.common.BalanceService;
import ru.bitel.bgbilling.kernel.contract.balance.common.ChargeService;
import ru.bitel.bgbilling.kernel.contract.balance.common.PaymentService;
import ru.bitel.bgbilling.kernel.contract.balance.common.bean.Charge;
import ru.bitel.bgbilling.kernel.contract.balance.common.bean.ContractBalance;
import ru.bitel.bgbilling.kernel.contract.balance.common.bean.Payment;
import ru.bitel.bgbilling.modules.npay.server.Calculator;
import ru.bitel.bgbilling.server.util.Setup;
import java.sql.*;
import java.util.Calendar;
import java.util.GregorianCalendar;
public class ActionUtils {
protected Setup setup;
protected Connection connection;
public ActionUtils (Setup setup, Connection connection){
this.setup = setup;
this.connection = connection;
}
public void moveBalance(int cid1, int cid2, int uid) throws BGException {
ServerContext context = ServerContext.get();
BalanceService balanceService = context.getService(BalanceService.class, 0);
ChargeService chargeService = context.getService(ChargeService.class, 0);
PaymentService paymentService = context.getService(PaymentService.class, 0);
ContractManager cm = new ContractManager(connection);
Calendar calendar = new GregorianCalendar();
String mid = setup.get("custom.npay.mid");
if (mid == null || mid.equals("")) throw new BGMessageException("Параметр custom.npay.mid не определен в конфигурации.");
String setupChargeId = setup.get("custom.contract.wrap.charge.id");
if (setupChargeId == null || setupChargeId.equals("")) throw new BGMessageException("Параметр custom.contract.wrap.charge.id не определен в конфигурации.");
String setupPaymentId = setup.get("custom.contract.wrap.payment.id");
if (setupPaymentId == null || setupPaymentId.equals("")) throw new BGMessageException("Параметр custom.contract.wrap.charge.id не определен в конфигурации.");
int chargeId = Integer.parseInt(setupChargeId);
int paymentId = Integer.parseInt(setupPaymentId);
Calculator calculator = new Calculator();
calculator.setExecutingTime(calendar);
calculator.initTask(setup, 0, "mid=" + mid + "\nservice.set=" + 0 + "\ncomment=");
calculator.setCids(String.valueOf(cid1));
calculator.startTask();
ContractBalance balance = balanceService.contractBalanceGet(cid1, calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH)+1);
Charge charge = new Charge(0, uid, cid1, chargeId, calendar.getTime(), "Перенос средств на договор №" + cm.getContractById(cid2).getTitle(), balance.toBalance(), calendar.getTime());
chargeService.chargeUpdate(charge);
Payment payment = new Payment(0, uid, cid2, paymentId, calendar.getTime(), "Перенесено с договора №" + cm.getContractById(cid1).getTitle(), balance.toBalance(), calendar.getTime());
paymentService.paymentUpdate(payment, null);
}
}
_________________
Код:
Клиент: вер. 6.2.874 / 05.02.2018 12:48:36
os: Windows 7; java: Java HotSpot(TM) 64-Bit Server VM, v.1.8.0_151
Сервер: вер. 6.2.1203 / 05.02.2018 12:50:34
os: Linux; java: Java HotSpot(TM) 64-Bit Server VM, v.1.8.0_45