Beispiel #1
0
// 顧客情報を保存します。
func SaveCustomer(customer *Customer) (*Customer, error) {
	db, err := common.GetDB()
	if err != nil {
		panic(err.Error())
	}
	defer db.Close()

	pp.Println(customer)

	var existCustomer Customer
	db.Where("ID = ?", customer.ID).First(&existCustomer)

	pp.Println(existCustomer)

	if existCustomer.ID != "" {
		// 更新
		customer.UpdatedAt = time.Now()
		db.Model(&customer).Where("ID = ?", customer.ID).Update(customer)
	} else {
		// 新規登録
		customer.ID = uuid.NewV4().String()
		customer.CreatedAt = time.Now()
		db.Create(&customer)
	}

	return customer, err
}
Beispiel #2
0
// 顧客情報を削除します。
func DeleteCustomer(customer *Customer) (*Customer, error) {
	db, err := common.GetDB()

	if err != nil {
		panic(err.Error())
	}
	defer db.Close()

	pp.Println("delete customer ID: " + customer.ID)

	db.Where("ID = ?", customer.ID).Delete(Customer{})

	return customer, err
}
Beispiel #3
0
// 顧客情報を取得します。
func GetCustomer() []Customer {
	db, err := common.GetDB()
	if err != nil {
		panic(err.Error())
	}
	defer db.Close()

	var customers []Customer
	db.Find(&customers)

	pp.Println(customers)

	return customers
}
Beispiel #4
0
// 消費税率データ取得
func GetTax() []Tax {
	db, err := common.GetDB()
	if err != nil {
		panic(err.Error())
	}
	defer db.Close()

	var taxResults []Tax
	db.Find(&taxResults)

	pp.Println(taxResults)

	return taxResults
}
Beispiel #5
0
// 消費税率データ保存
func SaveTax(tax *Tax) (*Tax, error) {
	db, err := common.GetDB()
	if err != nil {
		panic(err.Error())
	}
	defer db.Close()

	pp.Println(tax)

	var existTax Tax
	db.Where("ImplementationDate = ?", tax.ImplementationDate).First(&existTax)

	pp.Println(existTax)

	if existTax.ImplementationDate != "" {
		// ImplementationDateに紐づくデータが存在する場合、更新
		db.Model(&tax).Where("ImplementationDate = ?", tax.ImplementationDate).Update("TaxRate", tax.TaxRate)
	} else {
		// 存在しない場合、新規登録
		db.Create(&tax)
	}

	return tax, err
}