Browse Source

Shoop CP orders progress, fixes

Vova Tkach 5 years ago
parent
commit
da452dc054
4 changed files with 139 additions and 6 deletions
  1. 2 2
      modules/module_index_act_mysql_setup.go
  2. 133 0
      modules/module_shop.go
  3. 2 2
      support/migrate/000000015.go
  4. 2 2
      support/schema.sql

+ 2 - 2
modules/module_index_act_mysql_setup.go

@@ -286,8 +286,8 @@ func (this *Modules) RegisterAction_IndexMysqlSetup() *Action {
 				client_last_name varchar(64) NOT NULL COMMENT 'Client last name',
 				client_first_name varchar(64) NOT NULL COMMENT 'Client first name',
 				client_second_name varchar(64) NOT NULL DEFAULT '' COMMENT 'Client second name',
-				client_phone varchar(64) NOT NULL DEFAULT '' COMMENT 'Client phone',
-				client_email varchar(20) NOT NULL COMMENT 'Client email',
+				client_phone varchar(20) NOT NULL DEFAULT '' COMMENT 'Client phone',
+				client_email varchar(64) NOT NULL COMMENT 'Client email',
 				client_delivery_comment text NOT NULL COMMENT 'Client delivery comment',
 				client_order_comment text NOT NULL COMMENT 'Client order comment',
 				status int(1) NOT NULL COMMENT 'new/confirmed/canceled/inprogress/completed',

+ 133 - 0
modules/module_shop.go

@@ -313,6 +313,21 @@ func (this *Modules) shop_GetParentProduct(wrap *wrapper.Wrapper, id int) string
 	return result
 }
 
+func (this *Modules) shop_GetOrderStatus(status int) string {
+	if status == 0 {
+		return `<span style="color:#f0ad4e;">New</span>`
+	} else if status == 1 {
+		return `<span style="color:#28a745;">Confirmed</span>`
+	} else if status == 2 {
+		return `<span style="color:#d9534f;">Canceled</span>`
+	} else if status == 3 {
+		return `<span style="color:#f0ad4e;">In progress</span>`
+	} else if status == 4 {
+		return `<span style="color:#6c757d;">Completed</span>`
+	}
+	return "Unknown"
+}
+
 func (this *Modules) RegisterModule_Shop() *Module {
 	return this.newModule(MInfo{
 		WantDB: true,
@@ -337,6 +352,9 @@ func (this *Modules) RegisterModule_Shop() *Module {
 			{Mount: "currencies", Name: "List of currencies", Show: true, Icon: assets.SysSvgIconList},
 			{Mount: "currencies-add", Name: "Add new currency", Show: true, Icon: assets.SysSvgIconPlus},
 			{Mount: "currencies-modify", Name: "Modify currency", Show: false},
+			{Sep: true, Show: true},
+			{Mount: "orders", Name: "List of orders", Show: true, Icon: assets.SysSvgIconList},
+			{Mount: "orders-modify", Name: "Viewing order", Show: false},
 		},
 	}, func(wrap *wrapper.Wrapper) {
 		if len(wrap.UrlArgs) == 3 && wrap.UrlArgs[0] == "shop" && wrap.UrlArgs[1] == "category" && wrap.UrlArgs[2] != "" {
@@ -912,6 +930,121 @@ func (this *Modules) RegisterModule_Shop() *Module {
 				nil,
 				true,
 			)
+		} else if wrap.CurrSubModule == "orders" {
+			content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{
+				{Name: "Orders", Link: "/cp/" + wrap.CurrModule + "/" + wrap.CurrSubModule + "/"},
+				{Name: "List of orders"},
+			})
+			content += builder.DataTable(
+				wrap,
+				"shop_orders",
+				"id",
+				"DESC",
+				&[]builder.DataTableRow{
+					{
+						DBField:     "id",
+						NameInTable: "Order #",
+					},
+					{
+						DBField: "client_phone",
+					},
+					{
+						DBField: "update_datetime",
+					},
+					{
+						DBField: "currency_id",
+					},
+					{
+						DBField: "currency_name",
+					},
+					{
+						DBField: "currency_coefficient",
+					},
+					{
+						DBField: "currency_code",
+					},
+					{
+						DBField: "currency_symbol",
+					},
+					{
+						DBField:     "client_last_name",
+						NameInTable: "Client / Contact",
+						CallBack: func(values *[]string) string {
+							link := "/cp/" + wrap.CurrModule + "/orders-modify/" + (*values)[0] + "/"
+
+							last_name := html.EscapeString((*values)[8])
+							first_name := html.EscapeString((*values)[9])
+							second_name := html.EscapeString((*values)[10])
+
+							phone := html.EscapeString((*values)[1])
+							email := html.EscapeString((*values)[12])
+
+							name := ""
+							if last_name != "" {
+								name += " " + last_name
+							}
+							if first_name != "" {
+								name += " " + first_name
+							}
+							if second_name != "" {
+								name += " " + second_name
+							}
+							name = `<a href="` + link + `">` + strings.TrimSpace(name) + `</a>`
+
+							contact := ""
+							if email != "" {
+								contact += " " + email
+							}
+							if phone != "" {
+								contact += " (" + phone + ")"
+							}
+							contact = `<a href="` + link + `">` + strings.TrimSpace(contact) + `</a>`
+
+							return `<div>` + name + `</div><div><small>` + contact + `</small></div>`
+						},
+					},
+					{
+						DBField: "client_first_name",
+					},
+					{
+						DBField: "client_second_name",
+					},
+					{
+						DBField:     "create_datetime",
+						DBExp:       "UNIX_TIMESTAMP(`create_datetime`)",
+						NameInTable: "Date / Time",
+						Classes:     "d-none d-lg-table-cell",
+						CallBack: func(values *[]string) string {
+							t := int64(utils.StrToInt((*values)[11]))
+							return `<div>` + utils.UnixTimestampToFormat(t, "02.01.2006") + `</div>` +
+								`<div><small>` + utils.UnixTimestampToFormat(t, "15:04:05") + `</small></div>`
+						},
+					},
+					{
+						DBField:     "client_email",
+						NameInTable: "Status / Total",
+						CallBack: func(values *[]string) string {
+							status := this.shop_GetOrderStatus(utils.StrToInt((*values)[15]))
+							total := utils.Float64ToStr(0) + " " + html.EscapeString((*values)[6])
+							return `<div>` + status + `</div><div><small>` + total + `</small></div>`
+						},
+					},
+					{
+						DBField: "client_delivery_comment",
+					},
+					{
+						DBField: "client_order_comment",
+					},
+					{
+						DBField: "status",
+					},
+				},
+				nil,
+				"/cp/"+wrap.CurrModule+"/"+wrap.CurrSubModule+"/",
+				nil,
+				nil,
+				true,
+			)
 		} else if wrap.CurrSubModule == "add" || wrap.CurrSubModule == "modify" {
 			if wrap.CurrSubModule == "add" {
 				content += this.getBreadCrumbs(wrap, &[]consts.BreadCrumb{

+ 2 - 2
support/migrate/000000015.go

@@ -19,8 +19,8 @@ func Migrate_000000015(db *sqlw.DB, host string) error {
 			client_last_name varchar(64) NOT NULL COMMENT 'Client last name',
 			client_first_name varchar(64) NOT NULL COMMENT 'Client first name',
 			client_second_name varchar(64) NOT NULL DEFAULT '' COMMENT 'Client second name',
-			client_phone varchar(64) NOT NULL DEFAULT '' COMMENT 'Client phone',
-			client_email varchar(20) NOT NULL COMMENT 'Client email',
+			client_phone varchar(20) NOT NULL DEFAULT '' COMMENT 'Client phone',
+			client_email varchar(64) NOT NULL COMMENT 'Client email',
 			client_delivery_comment text NOT NULL COMMENT 'Client delivery comment',
 			client_order_comment text NOT NULL COMMENT 'Client order comment',
 			status int(1) NOT NULL COMMENT 'new/confirmed/canceled/inprogress/completed',

+ 2 - 2
support/schema.sql

@@ -108,8 +108,8 @@ CREATE TABLE shop_orders (
 	client_last_name varchar(64) NOT NULL COMMENT 'Client last name',
 	client_first_name varchar(64) NOT NULL COMMENT 'Client first name',
 	client_second_name varchar(64) NOT NULL DEFAULT '' COMMENT 'Client second name',
-	client_phone varchar(64) NOT NULL DEFAULT '' COMMENT 'Client phone',
-	client_email varchar(20) NOT NULL COMMENT 'Client email',
+	client_phone varchar(20) NOT NULL DEFAULT '' COMMENT 'Client phone',
+	client_email varchar(64) NOT NULL COMMENT 'Client email',
 	client_delivery_comment text NOT NULL COMMENT 'Client delivery comment',
 	client_order_comment text NOT NULL COMMENT 'Client order comment',
 	status int(1) NOT NULL COMMENT 'new/confirmed/canceled/inprogress/completed',