添加搜索字段以查看销售点中的特定报告

时间:2016-01-30 07:53:38

标签: php sql

我正在开发销售点。我有一个利润报告模块,我可以通过输入日期显示利润报告。现在我还想添加搜索字段,可以搜索产品和日期的特定供应商的报告。以下代码只显示按日期获利,帮我添加搜索supplier_id和此查询中的日期?

数据库疯了 表stock_details的表结构 列类型Null默认链接到注释 id int(10)没有
stock_id varchar(120)没有
stock_name varchar(120)否
stock_quatity int(11)否
supplier_id varchar(250)否
company_price decimal(10,2)否
selling_price十进制(10,2)否
category varchar(120)否
日期时间戳否CURRENT_TIMESTAMP
expire_date datetime否
uom varchar(120)否

表stock_sales的表结构 列类型Null默认链接到注释 id int(10)没有
transactionid varchar(250)否
stock_name varchar(200)否
category varchar(120)否
supplier_name varchar(200)否
selling_price十进制(10,2)否
小数(10,2)否
小数(10,2)否
日期日期否
username varchar(120)否
customer_id varchar(120)否
小计小数(10,2)否
付款小数(10,2)否
余额十进制(10,2)否
折扣小数(10,0)否
税小数(10,0)否
tax_dis varchar(100)否
dis_amount decimal(10,0)否
grand_total decimal(10,0)否
截止日期否
mode varchar(250)否
description varchar(500)没有
count1 int(11)否
billnumber varchar(120)否



//detail_profit_report.php
$result = $db->query("SELECT * FROM stock_sales where date BETWEEN '$fromdate' AND '$todate' ");

                    
                                    while ($line = $db->fetchNextObject($result)) {
                                        ?>

                                        <tr>
                                            <td><?php $mysqldate = $line->date;
                                                $phpdate = strtotime($mysqldate);
                                                $phpdate = date("d/m/Y", $phpdate);
                                                echo $phpdate; ?></td>

                                            <td><?php echo $line->transactionid; ?></td>
                                            <td><?php echo $line->stock_name; ?></td>
                                            <td>


<?php

$nam=$line->stock_name;
$t="select supplier_id from stock_details where stock_name='$nam'";
$result2 = mysqli_query($db->connection, $t);
 while ($row2 = mysqli_fetch_array($result2)) {
echo $row2['supplier_id'];
}


?>

</td>
                                            
 <td><?php echo $line->quantity; ?></td>
                                                                                       
<td>

<?php

$nam=$line->stock_name;
$t="select * from stock_details where stock_name='$nam'";
$result2 = mysqli_query($db->connection, $t);
//$profit=0;
 while ($row2 = mysqli_fetch_array($result2)) {
$profit=$profit+(($row2['selling_price']-$row2['company_price'])*$line->quantity);
echo (($row2['selling_price']-$row2['company_price'])*$line->quantity);

}


?>

</td>
                                            
                                        </tr>
&#13;
&#13;
&#13;

&#13;
&#13;
//view_report.php
function detail_profit_report_fn() {
            window.open("detail_profit_report.php?from_detail_profit_date=" + $('#from_detail_profit_date').val() + "&to_detail_profit_date=" + $('#to_detail_profit_date').val(), "myNewWinsr", "width=620,height=800,toolbar=0,menubar=no,status=no,resizable=yes,location=no,directories=no,scrollbars=yes");

        }
<form action="detail_profit_report.php" method="post" name="form1" id="form1" name="detail_profit_report"
                                  id="detail_profit_report" target="myNewWinsr">
                                <tr>

                                    <td><strong>Detail Profit </strong></td>
                                    <td>From</td>
                                    <td><input name="from_detail_profit_date" type="text" id="from_detail_profit_date"
                                               style="width:80px;"></td>
                                    <td>To</td>
                                    <td><input name="to_detail_profit_date" type="text" id="to_detail_profit_date" style="width:80px;">
                                    </td>
                                    <td><input name="submit" type="button" value="Show" onClick='detail_profit_report_fn();'>
                                    </td>
                                   <td> <input name="searchtxt" type="text" class="round my_text_box" placeholder="Search">
                           
</td>
                                </tr>

                            </form>  
&#13;
&#13;
&#13;

2 个答案:

答案 0 :(得分:0)

您只需稍加修改就可以使用以前的查询

    SELECT * FROM stock_sales where date BETWEEN('$fromdate' AND '$todate') AND supplier_id='$supplier_id' ;

答案 1 :(得分:0)

尝试此查询作为定义的要求

select stock_sales.id,stock_sales.transactionid,stock_sales.stock_name,
stock_sales.catgory,stock_sales.supplier_name,
stock_sales.selling_price,stock_sales.quantity,stock_sales.amount
,stock_sales.date,stock_sales.username,stock_sales.customer_id,
stock_sales.subtoal,stock_sales.payment,stock_sales.balance,
,stock_sales.discount,stock_sales.tax,stock_sales.tax_dis,stock_sales.dis_amount
,stock_sales.grand_total,stock_sales.due,stock_sales.mode,
stock_sales.description,stock_sales.count1,stock_sales.billnumber from stock_sales, stock_details where stock_details.stock_name like skock_details.stock_name
and date between ____________
and supplier_id = '$supplier_id'