首页 文章

创建发票号

提问于
浏览
0

我有这个问题我不知道如何创建发票编号 . 我希望它能像这样工作:

  • 我下载了从桌面发票中支付的所有发票,付款状态为OK的发票 .

  • 我从invoice_order下载了最高的数字,我将其添加到1并创建下一个数字,这意味着付款的发票号码= OK

  • 在发票/ invoice_order表中保存新发票号

  • 并且每当有新的付款发票时都这样,所以在给定月份内有连续性

你对如何使这项工作有任何想法吗?

$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>';  
        }          



    }

1 回答

  • 0

    理解这个问题有点困难,但我认为你想要一张发票连续收到 order_number 一旦付款a)无论付款何时支付或b)每月重新设定的数字 .

    如果A(每个invoice_order都是唯一的)

    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;
    

    小提琴:https://www.db-fiddle.com/f/ccS723rK7vCjdJBdDihjj6/0

相关问题