php pos inventory:如果数量为0,则不显示结果

时间:2013-10-20 17:44:28

标签: php

我目前正在修改开源PHP POS,我想修改代码而不是显示警告并显示0个库存项目,如果数量为0则不显示结果。

我设法将消息从正常消息更改为javascript弹出窗口但是我仍然不想显示该项目。因为使用这个系统的我的工作人员总是忽略弹出窗口,而当月底它显示了相当多的负面项目并且让我难以检查和改变。因此,我在这里寻求专业帮助,为我提供建议和帮助。我看起来高低,并设法得到一堆代码,我相信它可能是那个。如果我错了,请纠正我。

代码:

function add_item($item_id,$quantity=1,$discount=0,$price=null,$description=null,$serialnumber=null)
{
    //make sure item exists
    if(!$this->CI->Item->exists($item_id))
    {
        //try to get item id given an item_number
        $item_id = $this->CI->Item->get_item_id($item_id);

        if(!$item_id)
            return false;
    }


    //Alain Serialization and Description

    //Get all items in the cart so far...
    $items = $this->get_cart();

    //We need to loop through all items in the cart.
    //If the item is already there, get it's key($updatekey).
    //We also need to get the next key that we are going to use in case we need to add the
    //item to the cart. Since items can be deleted, we can't use a count. we use the highest key + 1.

    $maxkey=0;                       //Highest key so far
    $itemalreadyinsale=FALSE;        //We did not find the item yet.
    $insertkey=0;                    //Key to use for new entry.
    $updatekey=0;                    //Key to use to update(quantity)

    foreach ($items as $item)
    {
        //We primed the loop so maxkey is 0 the first time.
        //Also, we have stored the key in the element itself so we can compare.

        if($maxkey <= $item['line'])
        {
            $maxkey = $item['line'];
        }

        if($item['item_id']==$item_id)
        {
            $itemalreadyinsale=TRUE;
            $updatekey=$item['line'];
        }
    }

    $insertkey=$maxkey+1;

    //array/cart records are identified by $insertkey and item_id is just another field.
    $item = array(($insertkey)=>
    array(
        'item_id'=>$item_id,
        'line'=>$insertkey,
        'name'=>$this->CI->Item->get_info($item_id)->name,
        'item_number'=>$this->CI->Item->get_info($item_id)->item_number,
        'description'=>$description!=null ? $description: $this->CI->Item->get_info($item_id)->description,
        'serialnumber'=>$serialnumber!=null ? $serialnumber: '',
        'allow_alt_description'=>$this->CI->Item->get_info($item_id)->allow_alt_description,
        'is_serialized'=>$this->CI->Item->get_info($item_id)->is_serialized,
        'quantity'=>$quantity,
        'discount'=>$discount,
        'price'=>$price!=null ? $price: $this->CI->Item->get_info($item_id)->unit_price
        )
    );

    //Item already exists and is not serialized, add to quantity
    if($itemalreadyinsale && ($this->CI->Item->get_info($item_id)->is_serialized ==0) )
    {
        $items[$updatekey]['quantity']+=$quantity;
    }
    else
    {
        //add to existing array
        $items+=$item;
    }

    $this->set_cart($items);
    return true;

}

function out_of_stock($item_id)
{
    //make sure item exists
    if(!$this->CI->Item->exists($item_id))
    {
        //try to get item id given an item_number
        $item_id = $this->CI->Item->get_item_id($item_id);

        if(!$item_id)
            return false;
    }

    $item = $this->CI->Item->get_info($item_id);
    $quanity_added = $this->get_quantity_already_added($item_id);

    if ($item->quantity - $quanity_added < 0)
    {
        return true;
    }

    return false;
}

提前谢谢! 杰夫

2 个答案:

答案 0 :(得分:0)

你只显示前端的代码(“模板”),不幸的是这段代码显然缺少一些部分 - 至少表格行应该在那里。

但是我认为缺少的</tr>元素会出现在代码片段之后。

我在这里所做的只是将包含产品的<tr>置于一个条件中,这样只有当库存数量为&gt;时才会显示它。 0

<div id="register_wrapper">
<?php echo form_open("sales/change_mode",array('id'=>'mode_form')); ?>
    <span><?php echo $this->lang->line('sales_mode') ?></span>
<?php echo form_dropdown('mode',$modes,$mode,'onchange="$(\'#mode_form\').submit();"'); ?>
<div id="show_suspended_sales_button">
    <?php echo anchor("sales/suspended/width:425",
    "<div class='small_button'><span style='font-size:73%;'>".$this->lang->line('sales_suspended_sales')."</span></div>",
    array('class'=>'thickbox none','title'=>$this->lang->line('sales_suspended_sales')));
    ?>
</div>
</form>
<?php echo form_open("sales/add",array('id'=>'add_item_form')); ?>
<label id="item_label" for="item">

<?php
if($mode=='sale')
{
echo $this->lang->line('sales_find_or_scan_item');
}
else
{
    echo $this->lang->line('sales_find_or_scan_item_or_receipt');
}
?>
</label>
<?php echo form_input(array('name'=>'item','id'=>'item','size'=>'40'));?>
<div id="new_item_button_register" >
        <?php echo anchor("items/view/-1/width:360",
        "<div class='small_button'><span>".$this->lang->line('sales_new_item')            </span></div>",
        array('class'=>'thickbox none','title'=>$this->lang-    >line('sales_new_item')));
        ?>
    </div>

</form>
<table id="register">
<thead>
<tr>
<th style="width:11%;"><?php echo $this->lang->line('common_delete'); ?></th>
<th style="width:30%;"><?php echo $this->lang->line('sales_item_number'); ?></th>
<th style="width:30%;"><?php echo $this->lang->line('sales_item_name'); ?></th>
<th style="width:11%;"><?php echo $this->lang->line('sales_price'); ?></th>
<th style="width:11%;"><?php echo $this->lang->line('sales_quantity'); ?></th>
<th style="width:11%;"><?php echo $this->lang->line('sales_discount'); ?></th>
<th style="width:15%;"><?php echo $this->lang->line('sales_total'); ?></th>
<th style="width:11%;"><?php echo $this->lang->line('sales_edit'); ?></th>
</tr>
</thead>
<tbody id="cart_contents">
<?php
if(count($cart)==0)
{
?>
<tr><td colspan='8'>
<div class='warning_message' style='padding:7px;'><?php echo $this->lang-    >line('sales_no_items_in_cart'); ?></div>
</tr></tr>
<?php
}
else
{
    foreach(array_reverse($cart, true) as $line=>$item)
{
    $cur_item_info = $this->Item->get_info($item['item_id']);

    // THIS IS THE CONDITION WHERE I CHECK THE AVAILABILITY STATE
    if ($cur_item_info->quantity > 0) {
        echo form_open("sales/edit_item/$line");
?>
    <tr>
    <td><?php echo anchor("sales/delete_item/$line",'['.$this->lang->line('common_delete').']');?></td>
    <td><?php echo $item['item_number']; ?></td>
    <td style="align:center;"><?php echo $item['name']; ?><br /> [<?php echo $cur_item_info->quantity; ?> in stock]</td>



        <?php if ($items_module_allowed)
        {
        ?>
            <td><?php echo form_input(array('name'=>'price','value'=>$item['price'],'size'=>'6'));?></td>
    <?php
    }
    else
    {
    ?>
        <td><?php echo $item['price']; ?></td>
        <?php echo form_hidden('price',$item['price']); ?>
    <?php
    }
    ?>

    <td>
    <?php
        if($item['is_serialized']==1)
        {
            echo $item['quantity'];
            echo form_hidden('quantity',$item['quantity']);
        }
        else
        {
            echo form_input(array('name'=>'quantity','value'=>$item['quantity'],'size'=>'2'));
        }
    ?>
    </td>
    </tr>
<?php
    // I assumed that there must be a table row closer (above)
    } // end if quantity > 0
?>

HTH

答案 1 :(得分:0)

关于新代码 - 你有一个名为“out_of_stock”的函数,我试着在add_item的开头调用这个函数。请注意,这只是猜测,因为我不知道您的商店系统的内在因素:

function add_item($item_id,$quantity=1,$discount=0,$price=null,$description=null,$serialnumber=null)
{
//make sure item exists
if(!$this->CI->Item->exists($item_id))
{
    //try to get item id given an item_number
    $item_id = $this->CI->Item->get_item_id($item_id);

    if(!$item_id)
        return false;
}

// add the out-of-stock check here
if (out_ot_stock($item_id)) {
    return false;
}

// continue with the rest of code