package controller

import (
	"bswas/utilities"
)

func InventoryFormat(data []map[string]string, requestType bool) ([]interface{}, [][]interface{})  {
	row := []interface{}{
		"货主","库位","产品编码","产品条码","商品名称","属性仓","质量状态","失效日期","批号",
	}
	if requestType == true {
		row = append(row,"移出数量","移入数量")
	}
	row = append(row,"在库数量","占用数量")
	list := make([][]interface{},len(data))
	for k,v := range data{
		line := make([]interface{},len(row))
		for index,column := range row {
			line[index] = v[column.(string)]
		}
		list[k] = line
	}
	return row, list
}

func InventoryAccountMissionFormat(data []map[string]string) ([]interface{}, [][]interface{})  {
	row := []interface{}{
		"库位","产品名","商品条码","商品编码","生产日期","失效日期","批号","盘点人","ERP属性仓","质量状态","库存数量",
		"可用数量","盘点数量","复盘数量","复盘差异","分配数量","状态",
	}
		column := map[string]int{
		"location" : 0,
		"commodity_name" : 1,
		"commodity_barcode" : 2,
		"commodity_sku" : 3,
		"produced_at" : 4,
		"valid_at" : 5,
		"batch_number" : 6,
		"stock_person" : 7,
		"erp_type_position" : 8,
		"quality" : 9,
		"stored_amount" : 10,
		"valid_amount" : 11,
		"verified_amount" : 12,
		"re_checked_amount" : 13,
		"difference_amount" : 14,
		"occupied_amount" : 15,
		"mark" : 16,

	}
	list := make([][]interface{},len(data))
	for k,v := range data{
		line := make([]interface{},len(row))
		for key,value := range column {
			line[value] = v[key]
		}
		list[k] = line
	}
	return row, list
}
func InventoryCompareFormat(data []map[string]string) ([]interface{}, [][]interface{})  {
	row := []interface{}{
		"货主","任务号","生产时间","商品名称","商品编码","商品条码","属性仓","质量状态","宝时库存","参考库存","差值",
	}
	column := map[string]int{
		"owner_name" : 0,
		"mission_code" : 1,
		"created_at" : 2,
		"commodity_name" : 3,
		"commodity_sku" : 4,
		"commodity_barcode_code" : 5,
		"custom_location" : 6,
		"quality" : 7,
		"amount_in_sys" : 8,
		"amount_in_compare" : 9,
		"differ" : 10,
	}
	list := make([][]interface{},len(data))
	for k,v := range data{
		line := make([]interface{},len(row))
		for key,value := range column {
			if key == "created_at" {
				line[value] = utilities.DateFormat(v[key],"2006-01-02T15:04:05Z")
				continue
			}
			line[value] = v[key]
		}
		list[k] = line
	}
	return row, list
}
