<commit_before>package services

import com.escalatesoft.subcut.inject.BindingModule
import play.api.db.slick.Session
import com.github.nscala_time.time.Imports._
import models.sunerp._
import play.api.db.slick.Config.driver.simple._
import org.scalautils._
import TripleEquals._
import utils.Options.optionLongEq
import com.github.tototoshi.slick.MySQLJodaSupport._

/**
 * The Class SoPhanCongService.
 *
 * @author <NAME>
 * @since 4/16/14 10:42 AM
 *
 */
trait SoPhanCongService {
  def initData(month: Int, phongBanId: Long)(implicit session: Session)

  def dayCopyData(month: Int, day: Int, phongBanId: Long)(implicit session: Session)
}

class SoPhanCongServiceImpl(implicit val bindingModule: BindingModule) extends SoPhanCongService {


  override def dayCopyData(month: Int, day: Int, phongBanId: Long)(implicit session: Session) {
    val date = LocalDate
      .now
      .withMonth(month)
      .withDayOfMonth(day)

    val targetDate = date.minusMonths(1)

    val query = for {
      soPhanCong <- SoPhanCongs
      soPhanCongExt <- soPhanCong.soPhanCongExt
      if soPhanCong.phongBanId === phongBanId && soPhanCong.ngayPhanCong === targetDate && soPhanCong.taskId.isNotNull
    } yield (soPhanCong, soPhanCongExt)

    for (tuple <- query.list()) {
      val (soPhanCong, soPhanCongExt) = tuple
      val extId = SoPhanCongExts.save(soPhanCongExt.copy(id = None))
      SoPhanCongs.save(soPhanCong.copy(id = None, ngayPhanCong = date, soPhanCongExtId = extId))
    }
  }

  def initData(month: Int, phongBanId: Long)(implicit session: Session) {
    val date = LocalDate.now.withMonth(month)
    val firstDayOfMonth = date.dayOfMonth().withMinimumValue()
    val lastDayOfMonth = date.dayOfMonth().withMaximumValue()
    val nhanViens = NhanViens.findByPhongBanId(phongBanId)
    val query = for (soPhanCong <- SoPhanCongs.khoiLuongMonthQueryRange(month, date.getYear)
                     if soPhanCong.phongBanId === phongBanId) yield soPhanCong<commit_msg>Add function copy data from same day of last month.<commit_after>package services

import com.escalatesoft.subcut.inject.BindingModule
import play.api.db.slick.Session
import com.github.nscala_time.time.Imports._
import models.sunerp._
import play.api.db.slick.Config.driver.simple._
import org.scalautils._
import TripleEquals._
import utils.Options.optionLongEq
import com.github.tototoshi.slick.MySQLJodaSupport._

/**
 * The Class SoPhanCongService.
 *
 * @author <NAME>
 * @since 4/16/14 10:42 AM
 *
 */
trait SoPhanCongService {
  def initData(month: Int, phongBanId: Long)(implicit session: Session)

  def dayCopyData(month: Int, day: Int, phongBanId: Long)(implicit session: Session)
}

class SoPhanCongServiceImpl(implicit val bindingModule: BindingModule) extends SoPhanCongService {


  override def dayCopyData(month: Int, day: Int, phongBanId: Long)(implicit session: Session) {
    val date = LocalDate
      .now
      .withMonth(month)
      .withDayOfMonth(day)

    val targetDate = date.minusMonths(1)

    val checkQuery = for {
      soPhanCong <- SoPhanCongs
      if soPhanCong.phongBanId === phongBanId && soPhanCong.ngayPhanCong === date
    } yield soPhanCong

    if (checkQuery.list().isEmpty) {
      val query = for {
        soPhanCong <- SoPhanCongs
        soPhanCongExt <- soPhanCong.soPhanCongExt
        if soPhanCong.phongBanId === phongBanId && soPhanCong.ngayPhanCong === targetDate && soPhanCong.taskId.isNotNull
      } yield (soPhanCong, soPhanCongExt)

      for (tuple <- query.list()) {
        val (soPhanCong, soPhanCongExt) = tuple
        val extId = SoPhanCongExts.save(soPhanCongExt.copy(id = None))
        SoPhanCongs.save(soPhanCong.copy(id = None, ngayPhanCong = date, soPhanCongExtId = extId))
      }
    }
  }

  def initData(month: Int, phongBanId: Long)(implicit session: Session) {
    val date = LocalDate.now.withMonth(month)
    val firstDayOfMonth = date.dayOfMonth().withMinimumValue()
    val lastDayOfMonth = date.dayOfMonth().withMaximumValue()
    val nhanViens = NhanViens.findByPhongBanId(phongBanId)
    val query = for (soPhanCong <- SoPhanCongs.khoiLuongMonthQueryRange(month, date.getYear)
                     if soPhanCong.phongBanId === phongBanId) yield soPhanCong
{'fraction_non_alphanumeric': 0.10227272727272728, 'fraction_numerical': 0.004734848484848485, 'mean_word_length': 3.9242424242424243, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2959870', 'n_tokens_mistral': 1550, 'n_tokens_neox': 1428, 'n_words': 294}