如何打印多个标签/使用多个ID进行打印?

问题描述 投票:0回答:1

我正在处理一个问题。我有一份打印机工作,用于打印单个标签,这很好。但是,现在我想设置订单,以便如果一个订单中有多个 store_item_products,我可以同时打印这两种不同商品的标签。我无法正确访问此内容,不幸的是我是初学者。对于我的问题中的任何错误,我深表歉意。感谢您的任何帮助。 我在后端收到此错误

SQLSTATE[22P02]: Invalid text representation: 7 ERROR:  invalid input syntax for type bigint: "445,440" (SQL: select * from "store_item_product" where "id" = 445,440 limit 1) {"userId":309,"exception":"[object] (Illuminate\\Database\\QueryException(code: 22P02): SQLSTATE[22P02]: Invalid text representation: 7 ERROR:  invalid input syntax for type bigint: \"445,440\" (SQL: select * from \"store_item_product\" where \"id\" = 445,440 limit 1) at /var/www/vendor/laravel/framework/src/Illuminate/Database/Connection.php:760)

这是我在 Laravel 的工作。

<?php

namespace Modules\Store\Jobs\ItemProduct;

use App\Models\User;
use App\Models\Device;
use Illuminate\Bus\Batchable;
use Illuminate\Bus\Queueable;
use App\Jobs\Nodes\UserNotice;
use App\Jobs\Nodes\PrintDocument;
use App\Libraries\DocumentLibrary;
use Illuminate\Support\Facades\Bus;
use Illuminate\Queue\InteractsWithQueue;
use Modules\Store\Models\StoreItemProduct;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;

class StorePrintItemProductLabelJob implements ShouldQueue
{
    use Batchable, Dispatchable, InteractsWithQueue, Queueable;

    /** @var StoreItemProduct */
    private $data;

    /** @var User */
    private $user;

    private $appID;
    private string $print;
    private string $ip;
    protected int $copy_quantity;
    protected int|null $device_id = null;
    private int $orientation = 5;


    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct(StoreItemProduct $data, string $ip, User $user, $appID, string $print, int $copy_quantity, int|null $device_id = null)
    {
        $this->data = $data;
        $this->user = $user;
        $this->appID = $appID;
        $this->print = $print;
        $this->ip = $ip;
        $this->copy_quantity = $copy_quantity;
        $this->device_id = $device_id;
    }
    public function handle(): void
    {

        /** print label for productlabel */

        $printDocumentLibrary = new DocumentLibrary();
        $printer = $printDocumentLibrary->retrieveDeviceForGivenActionTypeAndIP($this->print, $this->ip);

        if ($this->device_id) {
            $printer = Device::find($this->device_id)->name;
        }

        foreach($this->data->id as $item){
        $store_item_type = $item->store_item()->first()->store_item_type_id;
        $width = in_array($store_item_type, [1,2]) ? 98 : 58;
        $height = in_array($store_item_type, [1,2]) ? 148 : 28;

        if ($printer) {
            $nodes[] =  (new PrintDocument($this->data['path'], $printer))->setHeight($height)->setWidth($width);
            $nodes[] = new UserNotice($this->user, "success",  __("general.printer_printing") . " IP: " . $this->ip . " Printer: " . $printer, null, ["object" => "pack", "object_id" => $this->data['id']]);
        } else {
            $nodes[] = new UserNotice($this->user, "error",  __("general.printer_not_found") . " IP: " . $this->ip, null, ["object" => "pack", "object_id" => $this->data['id']]);
        }
        Bus::chain($nodes)->dispatch();
        }


    }

    /**
     * Handle a job failure.
     *
     * @param \Throwable $th
     * @return void
     */
    public function failed(\Throwable $th): void
    {
        UserNotice::dispatch($this->user, "error",  __("general.error"), $th->getMessage());
    }
}

这是我在 vue 中的组件,我在其中调用模态进行打印

<template>
      <data-table
      :settings="storeAmLagerOrderItemTableSettings"
      ref="storeAmLagerOrderItemTable"
    ></data-table>
</template>

<script>
import viewProductPdfModalLabel from "../Item/Product/Unit/PrintLabel/viewProductPdfModalLabel";
export default {
  props: {
    orderdata: { type: Object, required: true },
  },
  data() {
    return {
      id: this.orderdata.id,
      storeAmLagerOrderItemTableSettings: {
        fetchUrl: "/data/store/item/product/unit/",
        columns: [
          {
            key: "id",
            label: "store.unit_id",
            hidden: true
          },
          {
            key: "ean_20",
            label: "store.ean_20",
          },
          {
            key: "store_item_product.id",
            label: "store.product_id",
            hidden: true
          },
          {
            key: "store_item_product.store_item.id",
            label: "store.item_id",
            hidden: true
          },
          {
            key: "store_order_item.id",
            label: "store.order_item_id",
            hidden: true
          },
          {
            key: "store_order_item.store_order.order_num",
            label: "store.order_num",
            hidden: false
          },
          // {
          //   key: "store_item_product.name",
          //   label: "store.item_product_name",
          // },
          {
            key: "store_item_product.store_item.name",
            label: "store.item_product_name",
          },
          {
            key: "store_item_product.materialproduct.material.name",
            label: "store.material_product_name",
          },
          {
            key: "store_item_product.materialproduct.webwidth",
            label: "store.webwidth",
            hidden: this.hiddenColumnMaterialOnlyRollenMaterial()
          },
          {
            key: "store_item_product.materialproduct.display_name",
            label: "store.webwidth",
            hidden: this.hiddenColumnMaterialOnlySheets()
          },
          // {
          //   key: "store_supplier_product.quantity_per_unit",
          //   label: "store.per_unit",
          //   renderer: this.renderPerUnit,
          // },

          {
            key: "store_item_product.store_item.ean_code",
            label: "store.item_ean_code",
          },
          {
            key: "store_item_product.ean_code",
            label: "store.product_ean_code",
          },

          // {
          //   key: "ean_20",
          //   label: "store.container",
          // },

          {
            key: "quantity_sum_motion",
            label: "store.quantity_sum_motion_on_lager",
            hidden: false
          },

          // {
          //   key: "quantity_sum_motion",
          //   label: "store.quantity_sum_motion",
          // },
          // {
          //   key: "price",
          //   label: "store.price",
          // },
          // {
          //   key: "item_price",
          //   label: "store.sum_price",
          // },
          // {
          //   type: "event",
          //   key: "edit_order_item",
          //   callback: this.editOrderItem,
          //   //permissions: ["manage store"],
          //   icon: "fa-plus-minus",
          //   label: "general.edit",
          // },
          // {
          //   type: "event",
          //   key: "remove_order_item",
          //   callback: this.deleteOrderItem,
          //   //permissions: ["manage store"],
          //   icon: "fa-plus-minus",
          //   label: "general.remove",
          //   classes: "btn btn-danger btn-xs",
          // },


        ],
        actions: [
          {
            type: "event",
            key: "add",
            callback: this.viewProductLabel,
            permissions: ["show store","manage store"],
            icon: "fa-plus",
            label: "general.add",
          },
        ],
        defaultSearchParams: {
          "store_order_item.store_order_id": this.orderdata.id,
        },
        showSearch: false,
        showSearchColumn: true,
        showPageLength: true,
        //defaultSortBy: "ean_",
        //defaultOrder: "asc",
        defaultPerPage: 10,
        pageLengths: [5, 10, 25, 50, 100],
        columnId: "id",
      },
    };
  },
  methods: {
    hiddenColumnMaterialOnlyRollenMaterial() {
      let data = this.orderdata.store_order_items[0].store_item_product;
      if (data.store_item.store_item_type_id == 1) {
        return false;
      }
      return true;
    },
    hiddenColumnMaterialOnlySheets() {
      let data = this.orderdata.store_order_items[0].store_item_product;
      if (data.store_item.store_item_type_id == 2) {
        return false;
      }
      return true;
    },
    reload(){
      this.$refs.storeAmLagerOrderItemTable.reload();
    },
    viewProductLabel(rowdata) {
    console.log(this.orderdata.store_order_items);

    const storeItemProductIds = this.orderdata.store_order_items.map(item => item.store_item_product.id);

    console.log(storeItemProductIds);

    this.$modal.show(
      viewProductPdfModalLabel,
      {
        id: storeItemProductIds,
      },
      { width: "500" }
    );
  },
  },
};
</script>

这是打印模式

<template>
  <div>
  <div class="row">
    <div class="col-lg-12">
      <div class="">
        <div class="box-header">
          <h3 class="box-title">{{ $t("store.printed_doc") }}</h3>
        </div>
        <div class="box-body">
          <div class="col-md-12">
            <simple-form
                ref="form"
                :schema="printedFormSchema"
                :model="formModel"
                :is-new-model="true"
                :completed="onComplete"
                :submitFieldText="$t('store.printed')"
                :url="'/data/store/item/product/'+ id + '/print'"
            ></simple-form>
            <p>{{$t("store.printer_select_note")}}</p>
            <hr>
            <div class="row">
              <buttonAsset
        :settings="{
          groupClasses: 'col-md-12 col-sm-12 col-xs-12',
          classes: 'btn btn-info btn-block',
          permissions: ['show store', 'manage store'],
          label: $t('store.view_product_label'),
          icon: 'fa-sticky-note',
          callback: createPDF,
        }"
      ></buttonAsset>
    </div>
          </div>
        </div>

      </div>
    </div>
  </div>
</div>
</template>

<script>
export default {
props: {
  id: { type: Number, required: true },
},
data() {
  return {
    formModel: {
      id: this.id,
      user_id: null,
      copy_quantity: 1,
      device_id: this.selectedPrinterDefault,
      orientation: 5
    },
    printedFormSchema: {
      fields: [
        {
          type: "input",
          inputType: "number",
          label: "store.id",
          model: "id",
          required: true,
          validator: "number",
          visible: false
        },
        {
          type: "input",
          inputType: "number",
          label: "store.user_id",
          model: "user_id",
          required: true,
          validator: "number",
          visible: false
        },
        {
          type: "input",
          inputType: "number",
          label: "store.number_of_copies",
          model: "copy_quantity",
          required: true,
          validator: "number",
        },
        {
          type: "select",
          label: "devices.device_name",
          model: "device_id",
          selectOptions: {
            url: "/data/devices",
            name: "name",
            value: "id",
            per_page: 500,
            orderColumn: "name"
          }
        }
      ]
    },
  }
},
created() {
  this.formModel.user_id = this.$store.state.user.data.id;
},
methods: {

  createPDF() {
      this.$axios.get("/data/store/pdf/item_product_info/" + this.id, {
          params: {  appID: this.$appID },
        }).then((res) => {
          this.$notify({
            group: "app",
            title: this.$t('import.import_title'),
            text: this.$t('import.inprogress'),
            type: "info"
          });
        }).catch((error) => {
        this.$notify({
          group: "app",
          title: this.$t("general.error"),
          text: error.response.data.message,
          type: "error",
        });
      });
    },
  onComplete(){
    console.log('onComplete');
  }
},
computed: {
  boxTitle() {
    return "store.print_unit_or_created_pdf";
  },
},
};
</script>

这是模型 StoreItemProduct

<?php

namespace Modules\Store\Models;

use App\Models\BaseModel;
use App\Models\Materialproduct;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Support\Facades\Log;
use Modules\Store\Libraries\ItemProductLibrary;

class StoreItemProduct extends BaseModel
{
    use HasFactory;

    protected $table = 'store_item_product';

    protected $primaryKey = 'id';

    protected $fillable = [
        'id',
        'store_item_id',
        'materialproduct_id',
        'supplier_marking',
        'description',
        'quantity_per_unit',
        'reserved',
        'quantity_per_order',
        'quantity_in_order',
        'min_quantity',
        'max_quantity',
        'min_order',
        'ean_code',
        'quantity',
        'inactive',
        'store_item_product_category_id',
        'store_measurements_id',
        'store_measurements_motions_id'
    ];

    protected $casts = [
        'ean_code' => 'string',
        'quantity' => 'float',
        'min_quantity' => 'float',
        'max_quantity' => 'float',
        'min_order' => 'float',
        'quantity_to_order' => 'float',
        'quantity_in_order' => 'float',
        'quantity_per_unit' => 'float',
        'quantity_pre_order' => 'float',
        'reserved' => 'float',
        'unit_count' => 'float',
        'last_price' => 'float'
    ];

    protected $appends = ["unit_count","quantity_with_per_unit"];

    public static function booted()
    {
        static::updated(function ($store_item_product) {
            if ($store_item_product->isDirty(['quantity_per_unit', 'quantity_pre_order','quantity_in_order', 'quantity','reserved','min_quantity'])) {
                //self::updateSumContentUM($store_item_product);
                self::updateQuantityToOrder($store_item_product);
            }
        });

        static::created(function ($store_item_product) {
            if ($store_item_product->isDirty(['quantity_per_unit', 'quantity_pre_order','quantity_in_order', 'quantity','reserved','min_quantity'])) {
                //self::updateSumContentUM($store_item_product);
                self::updateQuantityToOrder($store_item_product);
            }
        });

        static::deleted(function ($store_item_product) {
            $this->updateSumQuatityToOrder($store_item_product);
        });
    }

    // /** update sum quantity from motions */
    // public static function updateSumContentUM($store_item_product)
    // {
    //     StoreItemProduct::where(['id' => $store_item_product->id])->update(
    //         [
    //             'sum_content_um' => 0, //intval($store_item_product->quantity) * intval($store_item_product->quantity_per_unit ?? 1),
    //             'quantity_to_order' => intval($store_item_product->min_quantity - $store_item_product->quantity)
    //         ]
    //     );
    // }

    public static function updateQuantityToOrder($store_item_product)
    {
        // $quantity_on_store = ($store_item_product->min_quantity * -1) + (($store_item_product->quantity +  $store_item_product->quantity_in_order) - $store_item_product->reserved);

        // if($quantity_on_store < 0){
        //     $quantity_to_order = $quantity_on_store * -1;
        // }else{
        //     $quantity_to_order = 0;
        // }

        Log::channel('storemodule')->info("quantity: ".$store_item_product->quantity);
        Log::channel('storemodule')->info("pre order: ".$store_item_product->quantity_pre_order);
        Log::channel('storemodule')->info("in order: ".$store_item_product->quantity_in_order);
        Log::channel('storemodule')->info("reserved: ".$store_item_product->reserved);



        $to_order =  ($store_item_product->quantity + $store_item_product->quantity_pre_order + $store_item_product->quantity_in_order) - $store_item_product->reserved;

        Log::channel('storemodule')->info("to order: ".$to_order);

        if($to_order < 0){
            $final_to_order = $to_order*-1;
            $quantity_min = 0;
            if($store_item_product->min_quantity > ($to_order*-1)){
                $quantity_min = $store_item_product->min_quantity??0 - ($to_order*-1);
                // if($store_item_product->min_quantity == 0){
                //     $final_to_order = $to_order*-1;
                // }else{

                // }
                // $final_to_order = 0;
            }
            $final_to_order = $final_to_order + $quantity_min ?? 0;
        }else{
            if($store_item_product->min_quantity > $to_order){
                $final_to_order = $store_item_product->min_quantity - $to_order;
                Log::channel('storemodule')->info("rozdil: ".($store_item_product->min_quantity - $to_order));
            }else{
                $final_to_order = 0;
            }

        }

        // Log::info("to_order_min: ".$to_order_min);

        // if ($to_order < 0) {
        //     $final_to_order = ($to_order - $to_order_min)*-1;
        // }else{
        //     $final_to_order = 0;
        // }

        Log::channel('storemodule')->info("final_to_order: ".$final_to_order);

        StoreItemProduct::where('id','=',$store_item_product->id)->update(
            [
                'quantity_to_order' => $final_to_order
            ]
        );

    }

    public function materialproduct()
    {
        return $this->belongsTo(Materialproduct::class, 'materialproduct_id', 'id');
    }

    public function store_item()
    {
        return $this->hasOne(StoreItem::class, 'id', 'store_item_id');
    }

    public function store_order_item()
    {
        return $this->hasMany(StoreOrderItem::class, 'store_item_product_id', 'id');
    }

    public function store_product_unit()
    {
        return $this->hasMany(StoreProductUnit::class, 'store_item_product_id', 'id');
    }

    public function measurement()
    {
        return $this->belongsTo(StoreMeasurements::class,'store_measurements_id', 'id');
    }

    public function measurement_motions()
    {
        return $this->belongsTo(StoreMeasurements::class,'store_measurements_motions_id', 'id');
    }

    public function  getUnitCountAttribute()
    {
        return StoreProductUnit::where('store_item_product_id', $this->id)->where('quantity_sum_motion', '>', 0)->count();
    }

    public function  getLastPriceAttribute(): float
    {
        $storeItemProduct = StoreItemProduct::find($this->id);
        $date = Carbon::now()->format('Y-m-d');
        return ItemProductLibrary::getPrice($storeItemProduct,$date);
    }

    public function prices(){
        return $this->hasMany(StoreProductPrice::class, "store_item_product_id", "id");
    }

    public function getQuantityWithPerUnitAttribute(){
        $storeItemProduct = StoreItemProduct::find($this->id)->first();
        return ($storeItemProduct->quantity ? $storeItemProduct->quantity : 1)/($storeItemProduct->quantity_per_unit ? $storeItemProduct->quantity_per_unit : 1);
    }
}
laravel vue.js jobs
1个回答
0
投票

问题出在前端;从前端向后端传输数据确实存在问题。

© www.soinside.com 2019 - 2024. All rights reserved.