我遇到了这个问题,我不知道如何创建发票编号。我希望它像这样工作:
您对如何进行这项工作有任何想法吗?
$year = date('Y');
$month = date('m');
$curent_date = date('Y-m-d');
$ask = $conn->createCommand("SELECT * FROM invoices WHERE payment = 'OK' "
. "AND invoice_month=$month AND invoice_year=$year");
$data = $ask->query();
while (($row = $data->read()) !== FALSE) {
if($row['invoice_suffix'] != 'KOR') {
echo $row['ID'].'<br>';
}
}
答案 0 :(得分:0)
这个问题有点难以理解,但是我想您希望发票一旦被支付要么连续order_number
要么a)不管何时支付 OR b)重置数字每个月。
如果是A(每个发票的订单都是唯一的)
UPDATE invoices t1,
(SELECT MAX(invoice_order)+1 as x FROM invoices WHERE payment = 'OK') t2
SET t1.payment = 'OK', t1.invoice_order = t2.x
WHERE t1.id = INVOICE_TO_BE_UPDATED;
如果是B(每个月都有一组新的重复订单编号)
UPDATE invoices t1,
(SELECT month, year, MAX(invoice_order)+1 as x FROM invoices WHERE payment = 'OK' GROUP BY month, year) t2
SET t1.payment = 'OK', t1.invoice_order = t2.x
WHERE t1.id = INVOICE_TO_BE_UPDATED AND t1.month = t2.month AND t1.year = t2.year;