Contact oCntc = new Contact(oConn, getString(DB.gu_contact));
if (oCntc.isNull(DB.sn_passport))
throw new SQLException("Legal document number not set for Contact "+getString(DB.gu_contact)+" at bookig for academic course "+getString(DB.gu_acourse));
Product oProd = new Product();
if (!oProd.load(oConn, new Object[]{getString(DB.gu_acourse)})) {
throw new SQLException("No product found for given academic course");
} else {
if (oProd.isNull(DB.id_currency)) {
throw new SQLException("Currency for product is not set");
}
if (oProd.isNull(DB.pr_list)) {
throw new SQLException("List price for product is not set");
}
}
DBSubset oAddrs = oCntc.getAddresses(oConn);
DBSubset oBanks = oCntc.getActiveBankAccounts(oConn);
Invoice oInvc = new Invoice();
oInvc.put(DB.gu_shop, sGuShop);
oInvc.put(DB.id_currency, oProd.get(DB.id_currency));
oInvc.put(DB.id_legal, oCntc.getString(DB.sn_passport));
oInvc.put(DB.de_order, Gadgets.left(getStringNull(DB.nm_acourse,"")+"/"+oCntc.getStringNull(DB.tx_name,"")+" "+oCntc.getStringNull(DB.tx_surname,""),100));
oInvc.put(DB.gu_contact, oCntc.getString(DB.gu_contact));
oInvc.put(DB.nm_client, Gadgets.left(oCntc.getStringNull(DB.tx_name,"")+" "+oCntc.getStringNull(DB.tx_surname,""),200));
if (oAddrs.getRowCount()>0) {
oInvc.put(DB.gu_bill_addr, oAddrs.getString(DB.gu_address,0));
if (!oAddrs.isNull(DB.tx_email,0)) {
oInvc.put(DB.tx_email_to, oAddrs.getString(DB.tx_email,0));
}
} // fi
if (oBanks.getRowCount()>0) {
oInvc.put(DB.nu_bank, oBanks.getString(DB.nu_bank_acc,0));
} // fi
oInvc.store(oConn);
oInvc.addProduct(oConn, oProd.getString(DB.gu_product), 1f);
oInvc.put(DB.im_subtotal, oInvc.computeSubtotal(oConn));
oInvc.put(DB.im_taxes, oInvc.computeTaxes(oConn));
oInvc.put(DB.im_total, oInvc.computeTotal(oConn));
oInvc.put(DB.im_paid, new BigDecimal(0d));